Most developers write a Dockerfile once, get it working, and never look at it again.
The result is usually an image that:
Ships build tools nobody needs in production
Includes devDependencies and source code that should never be there
Takes forever to rebuild after a one-line change
I recently built a Dockerfile for a full-stack monorepo (React client + Node server) that fixes all three. It's only about 40 lines, and every one of them has a reason.
Let me walk you through it.
The Big Idea: Don't Ship Your Kitchen
Think of a restaurant. The kitchen has knives, pans, and raw ingredients. The customer gets a finished plate.
A multi-stage build works the same way:
🔨 Stage 1: build
Compiles the frontend → ❌ Not shipped
📦 Stage 2: production-deps
Installs runtime packages only → ✅ Only node_modules shipped
🚀 Stage 3: final
Assembles the finished image → ✅ Shipped
Only the last stage becomes your image.…