- All Courses
- Docker Essentials
- Building Images
- Multi-stage builds
Multi-stage builds
A multi-stage build compiles in a stage that has the full toolchain, then copies just the output into a clean runtime stage.
Overview
Build in one image, ship another
A multi-stage build compiles in a stage that has the full toolchain, then copies just the output into a clean runtime stage. Compilers, headers, and development dependencies never reach production.
The size difference is often an order of magnitude, and the security difference is larger: a runtime image with no shell and no package manager offers an attacker very little to work with.
Stages can also be targeted directly, so the same Dockerfile can produce a fat development image with hot reloading and a minimal production one.
In this lesson you will:
- Separate build tools from the runtime image
- Copy only the artefacts you need
- Target a stage for development
Resources
Notes are not saved yet — they clear when you leave this page.
Layer caching and build speed
14m
Slimming and securing images
1h