Koskamo

Multi-stage builds keep images small

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

Multi-stage builds use multiple FROM statements in a single Dockerfile; each FROM can use a different base and begins a new stage of the build. You selectively copy artifacts from one stage into another with COPY --from, leaving behind everything you don't want in the final image, so the end result can be a tiny production image containing only the built binary with none of the build tools required to build it. Name stages with FROM <image> AS <name> and refer to the name in COPY --from so the copy doesn't break if instructions are reordered later; unnamed stages are referenced by integer index starting at 0 for the first FROM. You can stop at a specific build stage with docker build --target <name>, useful for keeping a debug stage with debugging symbols or tools alongside a lean production stage, and BuildKit only builds the stages that the target stage depends on. COPY --from can also copy artifacts from a separate image by local image name, a tag available locally or on a registry, or a tag ID, pulling the image if necessary. Scope: Dockerfile builds with BuildKit. Reviewed October 4, 2026.

Source and provenance

Original source
docs.docker.com
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.