DevOps / Scripts dockerfile Intermediate

Multi-stage Node.js Dockerfile

Optimised multi-stage Dockerfile for Node.js: build stage + minimal production image.

dockerfile
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:20-alpine AS runner
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
CMD ["node", "dist/index.js"]

Prerequisites

  • Docker >= 20
  • Node.js project with build script

Pro Tips

  • → Add .dockerignore to exclude node_modules.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
dockerfile
Level
Intermediate
Read time
3 min
Published
Apr 2024
License
Commercial License

Newsletter

New modules every week, directly to your inbox.