0
0
RemixHow-ToBeginner ยท 4 min read

How to Deploy Remix Using Docker: Step-by-Step Guide

To deploy a Remix app using Docker, create a Dockerfile that installs dependencies, builds the app, and runs it with a Node.js server. Then build the Docker image with docker build and run it using docker run. This packages your Remix app in a container for easy deployment.
๐Ÿ“

Syntax

A typical Dockerfile for Remix includes these parts:

  • Base image: Use a Node.js image to run your app.
  • Working directory: Set where your app files live inside the container.
  • Copy files: Copy your app code and package.json and package-lock.json to the container.
  • Install dependencies: Run npm install or yarn.
  • Build app: Run npm run build to compile Remix.
  • Expose port: Tell Docker which port your app listens on.
  • Start command: Run the server with npm start or node.
dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]
๐Ÿ’ป

Example

This example shows a full Dockerfile for a Remix app. It uses Node 18 Alpine for a small image, installs dependencies, builds the app, exposes port 3000, and starts the server.

After creating this file, run docker build -t remix-app . to build the image, then docker run -p 3000:3000 remix-app to start the container. Your Remix app will be available at http://localhost:3000.

dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]
Output
Server listening on http://localhost:3000
โš ๏ธ

Common Pitfalls

Missing build step: Forgetting to run npm run build means your app won't compile and run correctly inside Docker.

Not copying all files: Only copying package.json and package-lock.json without source files causes build errors.

Wrong port exposure: Remix defaults to port 3000; exposing or mapping the wrong port will make the app unreachable.

Using development server: Running npm run dev inside Docker is not recommended for production; use npm start or a Node server.

dockerfile
### Wrong way (missing build):
FROM node:18-alpine
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]

### Right way (with build):
FROM node:18-alpine
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]
๐Ÿ“Š

Quick Reference

  • Use node:18-alpine for a lightweight Node.js base image.
  • Always run npm run build before starting the server.
  • Expose port 3000 and map it to your host.
  • Use docker build -t your-app-name . to build the image.
  • Run with docker run -p 3000:3000 your-app-name.
โœ…

Key Takeaways

Create a Dockerfile that installs dependencies, builds, and starts your Remix app.
Use Node 18 Alpine as the base image for a small, efficient container.
Always run the build step inside Docker before starting the server.
Expose and map port 3000 to access your Remix app from outside the container.
Avoid running development servers inside Docker for production deployments.