Docker build best practices: smaller, safer images with reusable stages
Answer: Use multi-stage builds, reusable stages, and the right base image to build more efficiently.
Multi-stage builds
A multi-stage build reduces final image size by creating a cleaner separation between building and the final output.
Split Dockerfile instructions into distinct stages so the output only contains the files needed to run the application.
Using more than one stage can also run build steps in parallel.
When several images have a lot in common, a reusable stage can hold the shared components. Unique stages can be based on that reusable stage.
Docker only needs to build that common stage once, which uses host memory more efficiently and helps derivative images load more quickly.
Choosing a base image
A secure image starts with the right base image: pick a trusted source and keep it small.
Docker Official Images are a curated collection with clear documentation, promoted practices, and regular updates.
Verified Publisher images are maintained by organizations that partner with Docker, and Docker-Sponsored Open Source images come from projects in Docker's open source program.
Look for the badges that mark those programs when you pick a base.
A smaller base image downloads faster, shrinks your image, and reduces vulnerabilities brought in through dependencies.
You can also use one base image for building and unit testing, and a slimmer image for production.
See also
Claims
- id: C1 claim: Multi-stage builds let you reduce the size of your final image. source: S1 evidence: "Multi-stage builds let you reduce the size of your final image"
- id: C2 claim: Split stages so the output only contains the files needed to run the application. source: S2 evidence: "only contains the files that are needed to run the application"
- id: C3 claim: Choose a base image from a trusted source and keep it small. source: S1 evidence: "ensure it's built from a trusted source and keep it small"
Sources
- [S1] Docker build best practices. Docker, Inc.. https://docs.docker.com/build/building/best-practices/ . License: Apache License 2.0. Accessed 2026-11-26.
- [S2] Docker build best practices (source). Docker, Inc.. https://raw.githubusercontent.com/docker/docs/main/content/manuals/build/building/best-practices.md . License: Apache License 2.0. Accessed 2026-11-26.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Docker, Inc., Docker build best practices; Docker, Inc., Docker build best practices (source). Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Docker, Inc., Docker build best practices; Docker, Inc., Docker build best practices (source). Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc.
Cite this
iinventedlight. 2026. "Docker build best practices: smaller, safer images with reusable stages." iinventedlight Library, iil:note:r43w35nf, version of 2026-11-26. https://iinventedlight.com/library/notes/docker-build-best-practices/. License: CC-BY-4.0.
@misc{iil_note_r43w35nf,
author = {{iinventedlight}},
title = {{Docker build best practices: smaller, safer images with reusable stages}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-26},
url = {https://iinventedlight.com/library/notes/docker-build-best-practices/},
note = {Permanent ID iil:note:r43w35nf. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- docker-build-best-practices.schema.json (schema; CC-BY-4.0)
- docker-build-best-practices.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/docker-build-best-practices.md.