multi-stage build
also: multi-stage Docker build, Docker build stages
A Docker/container technique that uses multiple FROM statements in a single Dockerfile to create intermediate build stages, with only the final stage included in the resulting image, reducing image size and improving security.
Multi-stage builds allow you to use multiple base images within one Dockerfile, each marked by a FROM instruction. This lets you compile code, install build tools, or prepare artifacts in earlier stages without including them in the final image.
Only the last FROM stage (or an explicitly selected stage) becomes the final image. Intermediate stages are discarded after their artifacts are copied out, so large compilers, build tools, and source code don't bloat your production container.
Example: A Go application stage builds the binary using the full Go SDK, then a final stage copies just the compiled binary into a minimal alpine image. The result is a small, production-ready container without the Go toolchain.
Multi-stage builds are essential for keeping container images lean, speeding up deployments, and reducing the attack surface of deployed applications.