Skip to content
uencoder

Multi-Stage Build

Multi-stage builds use multiple FROM stages in a Dockerfile; the final stage copies only the needed artifacts, shrinking the image.

Purpose

Shrink the final image, separating build-time from runtime environments.

Mechanism

Build stages install compilers and dependencies to build artifacts. The final stage uses a minimal base image (alpine/distroless) and only COPYs the artifacts. Eliminates build tools, source code, and intermediate files.

Use cases

  • Image optimization
  • Security reduction
  • Docker best practices

Related terms

References