Multi-Stage Build
PronunciationMUL-tee-STAYJ BILD
Definition
A multi-stage build uses several FROM steps in one Dockerfile: heavy tools build the app in the first stage, and only the finished output is copied into a small final image.
Where you hear it
In Dockerfiles for Node, Go and Python apps, image-size reviews and security hardening.
Examples
The multi-stage build shrank the image from 1.2 GB to 150 MB.
Only copy the compiled binary into the final stage.
The first stage compiles the code with the full toolchain, and the final stage copies only the binary.
Common mistake
Copying the whole source tree into the final stage. That brings back the size and the secrets you wanted to leave behind.
Don't confuse with
A single-stage Dockerfile, where build tools stay in the image you ship.
Say it at work
- In a meeting or chat
Split this into build and runtime stages.
- In an email or ticket
Why is the image so big?
Keep exploring
More in DevOps & Cloud