Build stages versus runtime stages
A small example
FROM busybox:1.37 AS prepareWORKDIR /workCOPY notes.txt .RUN tr a-z A-Z < notes.txt > report.txtFROM busybox:1.37 AS runtimeCOPY --from=prepare /work/report.txt /report.txtCMD ["cat", "/report.txt"]The first stage converts a source note into an output file. The next FROM starts from BusyBox again, not from the filesystem of prepare. The copy transfers the report, not the entire work directory. A stage is a build step group, not a running service. Think of a kitchen and a packed lunch: the lunch contains the meal, not the cooking tools. Here both bases are identical to keep the exercise simple; a later lesson chooses different bases. A later FROM may also name an earlier stage and inherit its filesystem and configuration; this example deliberately starts from a separate base instead.
Try it in a local lab
Manual lab only. Use an approved fresh disposable Linux VM with blocked network egress, a local Engine and local Buildx docker driver. Check docker context show, docker version, docker buildx version and docker buildx ls. Confirm reviewed preloaded native busybox:1.37 and, for the scratch example, golang:1.26; verify actual digest, root build user, default entrypoint, required applets/compiler and frontend support. Tags are mutable; record actual identities. Stop if any dependency needs fetching or builder is remote. --network none limits RUN networking, not all builder traffic. Confirm all bm-v10 tags are unused, including checks and full. Execute commands individually in the specified fixture directory and stop on unexpected failure. All expected results are predictions. No secrets, host mounts or registry pushes. Before querying or building, confirm DOCKER_HOST, DOCKER_CONTEXT and BUILDX_BUILDER overrides and the effective endpoint are approved; do not contact an unapproved endpoint. docker build normally uses the Engine default builder, not necessarily the starred Buildx builder. Record the effective local docker driver and platform; review the synthetic context and ignore rules. After each build, require exit status zero before running its tag; an earlier tag may still exist after failure.
Open lab-fixtures/docker-multi-stage-images/01-stage-boundaries/ in the extracted archive. The Dockerfile and these files are supplied. Work on a disposable copy, not the original archive.
docker build --load --network none --progress=plain -t bm-v10-stage-boundaries:lab .docker run --rm --pull=never --network none bm-v10-stage-boundaries:labdocker run --rm --pull=never --network none bm-v10-stage-boundaries:lab sh -c "test -f /report.txt && test ! -e /work/notes.txt"Expect READY FOR DELIVERY on stdout. The second command should exit successfully without printing anything; the source note is absent. The builder may retain intermediate results in its cache.
Confirm the tag belongs to this lab and no containers depend on it. Remove only that tag without forcing. Cached data may remain; dispose of the VM rather than clearing a shared cache. Restore any edited fixture or discard the working copy.
Common mistake
Do not assume that every earlier stage is part of the delivered image or that intermediate files disappear from the builder. Never place secrets in a stage as a substitute for secret mounts.
Manual practice
Change notes.txt in the disposable copy, rebuild and predict the new report. Sketch prepare → report.txt → runtime, then identify the file that should be absent.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Build stages versus runtime stages — Knowledge check
Apply the multi-stage concept to a new scenario.
What begins a new stage?
What reaches the runtime stage in this example?
Where may intermediate build results still exist?