Docker multi-stage builds
Answer: With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them begins a new stage of the build. You can selectively copy artifacts from one stage to another, leaving behind everything you don't want in the final image. (S1)
What it buys you
- Multi-stage builds let you reduce the size of your final image, by creating a cleaner separation between the building of your image and the final output. (S2)
- In the docs example, the end result is a tiny production image with nothing but the binary inside. (S1)
- None of the build tools required to build the application are included in the resulting image. (S1)
- Using multiple stages can also let you build more efficiently by executing build steps in parallel. (S2)
Naming and sharing stages
- By default, the stages aren't named, and you refer to them by their integer number, starting with 0 for the first FROM instruction. (S1)
- However, you can name your stages, by adding an AS <NAME> to the FROM instruction. (S1)
- If you have multiple images with a lot in common, consider creating a reusable stage that includes the shared components. (S2)
- Docker only needs to build the common stage once. (S2)
Claims
- id: C1 claim: Multi-stage builds use multiple FROM statements. source: S1 evidence: "With multi-stage builds, you use multiple FROM statements in your Dockerfile."
- id: C2 claim: Each FROM begins a new build stage. source: S1 evidence: "Each FROM instruction can use a different base"
- id: C3 claim: Stages can be named with AS. source: S1 evidence: "you can name your stages, by adding an AS <NAME> to the FROM instruction."
- id: C4 claim: Multi-stage builds reduce the size of the final image. source: S2 evidence: "Multi-stage builds let you reduce the size of your final image"
Sources
- [S1] Multi-stage builds. Docker Docs. https://docs.docker.com/build/building/multi-stage/ . License: Docker docs, Apache-2.0 (github.com/docker/docs; https://github.com/docker/docs/blob/main/LICENSE); Docker name and logo are trademarks of Docker Inc and are not licensed. Accessed 2026-11-04.
- [S2] Building best practices. Docker Docs. https://docs.docker.com/build/building/best-practices/ . License: Docker docs, Apache-2.0 (github.com/docker/docs; https://github.com/docker/docs/blob/main/LICENSE); Docker name and logo are trademarks of Docker Inc and are not licensed. Accessed 2026-11-04.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Docker Docs, Multi-stage builds, Docker docs, Apache-2.0 (github.com/docker/docs; https://github.com/docker/docs/blob/main/LICENSE); Docker name and logo are trademarks of Docker Inc and are not licensed; Docker Docs, Building best practices, Docker docs, Apache-2.0 (github.com/docker/docs; https://github.com/docker/docs/blob/main/LICENSE); Docker name and logo are trademarks of Docker Inc and are not licensed.
Cite this
iinventedlight. 2026. "Docker multi-stage builds." iinventedlight Library, iil:note:mdfrayrz, version of 2026-11-04. https://iinventedlight.com/library/notes/docker-multi-stage-builds/. License: CC-BY-4.0.
@misc{iil_note_mdfrayrz,
author = {{iinventedlight}},
title = {{Docker multi-stage builds}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/docker-multi-stage-builds/},
note = {Permanent ID iil:note:mdfrayrz. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/docker-multi-stage-builds.md.