---
source: https://iinventedlight.com/library/notes/docker-multi-stage-builds.md
title: "Docker multi-stage builds"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_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; prose restates or closely paraphrases cited source lines"
license_family: docker-docs-apache
rule_check: "needs rule check (family not in auto-publish rule; check.mjs auto-approves only usgov and arxiv-ccby)"
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: Docker"
tags: ['docker', 'dockerfile', 'multi-stage', 'images']
sources:
  - id: S1
    title: "Multi-stage builds"
    publisher: Docker Docs
    url: https://docs.docker.com/build/building/multi-stage/
    accessed: 2026-11-04
    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"
  - id: S2
    title: "Building best practices"
    publisher: Docker Docs
    url: https://docs.docker.com/build/building/best-practices/
    accessed: 2026-11-04
    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"
---
# 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).
