patternModerate
Multi-stage Docker builds for minimal production images
Viewed 0 times
multi-stage buildDocker image sizeslimalpinedistrolessCOPY --from
Problem
Docker images are 1-2GB because they include build tools, dev dependencies, and source files.
Solution
Multi-stage: build in full image, copy output to minimal base. Node: FROM node:20 AS build, npm ci, npm run build. Then FROM node:20-slim, COPY --from=build. For Go: copy binary to scratch or distroless. Tips: use -slim or -alpine for final stage, use .dockerignore.
Why
Build tools are only needed during build. Production container only needs runtime and compiled output. Multi-stage separates these in a single Dockerfile.
Revisions (0)
No revisions yet.