Docker Multi-stage
Question
What is a multi-stage build in Docker?
Hint
Multi-stage builds separate build tools from the runtime image.
Explanation
A multi-stage build uses multiple FROM instructions in one Dockerfile to create smaller final images. Pattern: first stage (builder) compiles the app with build tools (npm, gcc, maven). Second stage (runtime) copies only the build output to a minimal base image. Benefits: 1) Smaller images (no build tools in final). 2) Better security (fewer tools = smaller attack surface). 3) Faster deployments. Example: Node.js — builder stage runs npm install && npm run build, final stage copies dist/ to nginx:alpine. Name stages with AS (FROM node:18 AS builder). COPY --from=builder copies from a previous stage.
Related Resources
Related Lessons
- Dockerfile
Learn Dockerfile.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.