How to Deploy Remix Using Docker: Step-by-Step Guide
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.jsonandpackage-lock.jsonto the container. - Install dependencies: Run
npm installoryarn. - Build app: Run
npm run buildto compile Remix. - Expose port: Tell Docker which port your app listens on.
- Start command: Run the server with
npm startornode.
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.
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"]
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.
### 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-alpinefor a lightweight Node.js base image. - Always run
npm run buildbefore 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.