§ GARDEN · DEVOPS · CLASS OPEN
NODE FILE · ENTRY
Docker Multi-Stage Builds for Node Apps
FILED UNDER · DEVOPS
①Read
②Meta
Shrink your production images by separating build dependencies from runtime — a practical Dockerfile walkthrough.
A naive Dockerfile installs all dependencies, builds the app, and ships everything — including devDependencies, build tools, and source files — in the final image. Multi-stage builds fix this: use one stage to build and another to run. The final image contains only production artifacts.
The Pattern
Stage 1: FROM node:20 AS builder — install all deps, run the build. Stage 2: FROM node:20-slim — copy only the build output and production node_modules. Your image goes from 1.2GB to 200MB. Layer caching means rebuilds only redo changed stages.
DTNRWORKSHOP ARMAMENTSSN 2012.OTT.0176