devops#docker#node#devops
The Perfect Dockerfile for Node.js Apps
Multi-stage builds, layer caching and a 90% smaller image size.
Series
Shipping Fast with Containers
The Perfect Dockerfile for Node.js
# Stage 1 — deps
FROM node:20-alpine AS deps
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile --production
# Stage 2 — build
FROM node:20-alpine AS build
WORKDIR /app
COPY . .
RUN yarn install --frozen-lockfile && yarn build
# Stage 3 — runtime
FROM node:20-alpine
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
USER node
CMD ["node", "dist/server.js"]
Result: ~120MB vs 900MB for a naive Dockerfile.
Keep reading
You may also like
devops
Git Handbook – Quick Reference
A complete collection of Git commands and notes, covering setup, commits, branching, merging, conflicts, and advanced workflows. This handbook is designed as a simple, step‑by‑step guide for beginners and professionals to quickly learn and apply Git in real projects.
Read
devops
Kubernetes Explained for Absolute Beginners
The clearest possible introduction to Kubernetes — what it is, why it exists, and the seven words you need to know.
Read
devops
GitHub Actions: A Complete CI Pipeline
Lint, test, build, publish — a battle-tested workflow template.
Read
Discussion (0)
No comments yet. Be the first to weigh in.