← All notes

Docker build garbage collection: periodic prune policies for BuildKit cache

Answer: Unlike docker builder prune or docker buildx prune, which run at once, garbage collection runs periodically, follows prune policies, and clears the build cache when size becomes too big or age expires.

How policies are applied

GC follows an ordered list of prune policies.

The daemon clears cache when it grows too large or when it gets too old.

Most users find the default GC behavior sufficient, with no intervention required.

People working on large-scale builds, self-managed builders, or constrained storage might benefit from customizing these settings.

Policies are evaluated in sequence, beginning with the most specific criteria, then broader rules if earlier policies do not free up enough cache.

That lets BuildKit prioritize cache entries, preserving valuable cache while the system maintains performance and availability.

One example finds stale records unused in the past 48 hours and deletes them until at most 5GB of stale cache is left; if total size then exceeds 10GB, more records are deleted until the total is no more than 10GB.

The first rule is narrower and targets less valuable stale cache; the second is a higher hard limit for any cache.

Default policies also drop regenerable cache such as local or Git contexts and unused cache mounts, plus unshared layer blobs, and finally any cache over the size limit.

Configuration

The precise algorithm and the means of configuring policies differ slightly depending on what kind of builder you're using.

If the defaults already work, you can skip custom setup.

A custom builder is configured with a BuildKit configuration file.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Docker, Inc., Build garbage collection; Docker, Inc., Build garbage collection (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., Build garbage collection; Docker, Inc., Build garbage collection (source). Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc.

Cite this

Permanent ID: iil:note:bytzcns8

iinventedlight. 2026. "Docker build garbage collection: periodic prune policies for BuildKit cache." iinventedlight Library, iil:note:bytzcns8, version of 2026-11-26. https://iinventedlight.com/library/notes/docker-build-cache-garbage-collection/. License: CC-BY-4.0.

@misc{iil_note_bytzcns8,
  author = {{iinventedlight}},
  title = {{Docker build garbage collection: periodic prune policies for BuildKit cache}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-26},
  url = {https://iinventedlight.com/library/notes/docker-build-cache-garbage-collection/},
  note = {Permanent ID iil:note:bytzcns8. License: CC-BY-4.0.},
}

Markdown

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.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/docker-build-cache-garbage-collection.md.