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.
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.
Similar Modules
Postgres S3 Backup
Dump a Postgres database, gzip it, push to S3 with AES256 encryption.
bash
·
Intermediate
Disk Usage Alert
Send an alert when any mounted filesystem exceeds a usage threshold.
bash
·
Beginner
Docker Image Cleanup Script
Remove dangling images, stopped containers and unused volumes in one pass.
bash
·
Intermediate