Multi-stage vs single-stage
Multi-stage builds separate the build environment from the runtime, discarding compilers and test tools from the final image.
Aspect | Single-stage | Multi-stage |
|---|
Final image size | Includes build tools (GBs) | Only runtime (MBs) |
Attack surface | Compilers, package managers | Runtime only |
Build cache reuse | Harder | Natural (one stage per concern) |
Complexity | Low | Moderate |
Best for | Dev/scratch images | Production images |