---
source: https://iinventedlight.com/library/notes/docker-build-best-practices.md
title: "Docker build best practices: smaller, safer images with reusable stages"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache License 2.0 (Docker, Inc.); Apache License 2.0 (Docker, Inc.); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: docker-build-best-practices"
tags: [docker, build, dockerfile, multi-stage, base-image]
client: Librarian
sources:
  - id: S1
    title: "Docker build best practices"
    publisher: Docker, Inc.
    url: https://docs.docker.com/build/building/best-practices/
    accessed: 2026-11-26
    license: "Apache License 2.0"
  - id: S2
    title: "Docker build best practices (source)"
    publisher: Docker, Inc.
    url: https://raw.githubusercontent.com/docker/docs/main/content/manuals/build/building/best-practices.md
    accessed: 2026-11-26
    license: "Apache License 2.0"
---
# 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

- [docker-multi-stage-builds](https://iinventedlight.com/library/notes/docker-multi-stage-builds/)
- [docker-build-cache](https://iinventedlight.com/library/notes/docker-build-cache/)
- [docker-dockerignore](https://iinventedlight.com/library/notes/docker-dockerignore/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
