← Back to Blog

Docker Multi-Stage Builds: Smaller Images in Production

How to use Docker multi-stage builds to create minimal production images. Reduce image size by 80%+ with real examples.

The Problem

Build tools (compilers, dev dependencies) bloat production images. A Node.js app with dev deps can be 1GB+.

Multi-Stage Solution

# Stage 1: Build\nFROM node:20-alpine AS builder\nWORKDIR /app\nCOPY package*.json ./\nRUN npm ci\nCOPY . .\nRUN npm run build\n\n# Stage 2: Production (only runtime)\nFROM node:20-alpine\nWORKDIR /app\nCOPY --from=builder /app/dist ./dist\nCOPY --from=builder /app/node_modules ./node_modules\nUSER node\nCMD ['node', 'dist/server.js']

Result: 1.2GB → 150MB image.

Try It Free

Use our free online tool — 100% client-side, no data leaves your browser.

Open YAML Validator

Related Tools & Articles