Docker build cache: prune the store that is full
Trace the failing write through context, builder and filesystem before choosing a cleanup command.
Quick answer
When a Docker build reports no space left, identify the builder and filesystem that own the failing write before pruning anything. `docker system df` describes a daemon's objects, while `docker buildx du` describes the selected builder's cache. Cleaning a different store can remove useful cache without relieving the failure.
On this page
When a Docker build reports no space left, identify the builder and filesystem that own the failing write before pruning anything. docker system df describes a daemon's objects, while docker buildx du describes the selected builder's cache. Cleaning a different store can remove useful cache without relieving the failure. [1][5]
Which store owns the failing build?#
The failing build's selected builder is the starting point. Record the Docker context, builder name, driver and node endpoint from the environment that actually runs the build. A command executed in an interactive terminal may select a different builder from a CI job, a remote session or a build wrapper.
Scenario: a fictional team has a local default builder and a named builder used by release jobs. A release build fails while importing a dependency layer. An operator inspects local Docker disk usage and runs a familiar cleanup command. The release job still fails because the operator has not yet established that the inspected store belongs to that job.
The first evidence to collect is the actual build invocation, including environment settings that select a context or builder. Then inspect the same selection explicitly. Do not start by copying a large reclaimable number into an incident ticket and treating it as the capacity available to the failed operation.
docker context show
docker buildx version
docker buildx ls
docker buildx inspect release-builder
docker buildx --builder release-builder du --verbose
docker system df -vrelease-builder is an illustrative name that must be replaced with the builder used by the failing job. These are inspection commands. The output should tell the operator where the build runs and which cache records belong to it; it does not authorize deleting every object that appears reclaimable.
For the docker-container driver, Docker documents a managed BuildKit container and a dedicated volume holding BuildKit state and cache. That volume is a different object from a service's database volume, even though both appear in Docker's resource inventory. Connect the builder to its actual state location before choosing a cleanup command. [4]
The same reasoning applies when the builder is remote. Free space on the laptop running the CLI does not establish free space at the builder's endpoint. Ask the owner of that endpoint for filesystem observations taken where the failing write occurs. Write the builder endpoint and filesystem path beside each capacity observation.
Follow an incident across two builders#
The worked case begins with competing explanations: the selected builder's cache is full, the daemon's image store is consuming capacity, or another consumer has filled the same filesystem. Follow the failed stage to its builder endpoint, then compare that store’s cache with the filesystem that rejected the write.
Scenario: the release job explicitly chooses release-builder. The operator's terminal initially chooses default. Inspecting both builders reveals that they do not share the same cache inventory. The team records each builder separately instead of adding their reported totals and assuming that the sum represents unique filesystem blocks.
buildx du identifies cache records and whether they are reclaimable or shared. Shared records need careful interpretation: removing a cache reference need not release every byte shown for that record if another resource still references the underlying data. Use the documented accounting and verify the resulting store, rather than predicting reclaimed physical space from a casual sum. [1]
The operator then asks which writes failed. Was the error reported by BuildKit while unpacking a layer, by the application running inside a build step, or by a separate export destination? Those locations can lead to different investigations. Preserve the error's path and stage, but remove credentials and sensitive build arguments from the incident record.
Suppose the selected builder's old, unused cache is the agreed candidate for deletion. Record the retention requirement before proceeding. The release team may need a warm compiler cache, an offline rebuild path or an expensive dependency download. An empty compiler cache may force another long download or rebuild. Agree on that cost before removing it.
What should be pruned, and what must be kept?#
Prune the approved cache scope using the named builder, after checking which flags the installed Buildx version supports. Docker's current command reference documents age and record filters, as well as space constraints. The available CLI options should be verified locally instead of assuming that a command copied from current documentation works on an older runner. [2]
# Inspection first; replace the example builder name.
docker buildx --builder release-builder du --verbose
docker buildx prune --help
# Mutation example: run only for the reviewed builder and retention rule.
# This retains the normal confirmation prompt.
docker buildx --builder release-builder prune --filter 'until=168h'
# Inspect the same store again.
docker buildx --builder release-builder du --verboseThe age in this example is an illustrative retention choice, not a recommended universal threshold. It refers to cache use under the documented filter semantics. It does not mean “delete everything from builds created before this time,” and it does not guarantee that the remaining candidates can satisfy a particular free-space target. [2]
Do not silently add --force, --all or broader system cleanup when the narrow command leaves insufficient room. Each changes either the confirmation behavior or deletion scope. Docker documents that the build-cache --all flag includes internal and frontend images; it should not be confused with the meaning of --all on every other Docker resource command. [2][6]
| Observed owner | Candidate action | Separate concern |
|---|---|---|
| Named builder cache | Review and prune that builder's eligible cache | Rebuild and download cost |
| Daemon image inventory | Review unused images and references | Required rollback images |
| Application volume | Follow the application's retention procedure | Authoritative data and backups |
| Unidentified filesystem consumer | Investigate the owner first | Cache deletion may be irrelevant |
docker system prune has a broader scope than a targeted builder-cache operation. Docker documents removal of stopped containers, unused networks, dangling images and unused build cache; volumes are not included by default. Treating it as a harmless synonym for cleaning one builder can remove objects that belong to a different operational purpose. [6]
Never use volume pruning as a substitute for understanding the storage owner. A volume that is currently unreferenced may still contain data an operator intends to recover or reuse. The article's maintenance example is scoped to approved cache records, not to application storage or a blanket host cleanup.
Why can reclaimed cache leave the disk full?#
A decrease in logical cache accounting and relief of the failing storage constraint are separate observations. First confirm that the cleanup ran against the same named builder and endpoint. Then inspect what changed in the affected filesystem. If the two observations disagree, preserve that discrepancy instead of declaring success from the command's summary alone.
Shared records are one documented reason that cache accounting can be misleading when interpreted as immediately recoverable physical bytes. Other possible branches include a different filesystem, another active writer, inode exhaustion or a virtual disk whose host allocation does not immediately shrink. These are hypotheses to investigate in the actual environment, not diagnoses established by this fictional case. [1]
For a Linux builder host, the following commands illustrate filesystem checks to run with the host owner's knowledge. The path is a placeholder for the confirmed state location. Docker Desktop, a managed CI runner or a remote build service may expose a different inspection interface; do not infer their storage layout from this Linux example.
# On the confirmed Linux builder host, for its actual storage path:
df -h /confirmed/buildkit/storage
df -i /confirmed/buildkit/storageThe first observation concerns byte capacity and the second inode capacity. Record which constraint is relevant to the failed write. A filesystem with available bytes can still have another exhausted resource, and freeing large cached objects may not address a problem dominated by many small files. The commands are diagnostic examples, not measurements taken from the reader's machine.
If a virtual machine's internal disk has more free space after cleanup but its host file remains large, that can be a separate space-reclamation problem. Follow the platform's documented maintenance path after identifying the platform and version. Do not remove files from Docker's internal stores manually or assume that shrinking a host file is the same operation as pruning BuildKit cache.
Retry the originally failing build only after the relevant capacity observation changes. A small unrelated image may build successfully while the release still cannot unpack or export its required layers. Use the real job or a representative approved reproduction, and record the stage that now passes. Avoid claiming a repair from a test that never reached the failed stage.
How should retention prevent another incident?#
Use recurring garbage collection at the actual builder when the observed growth comes from its cache. BuildKit GC runs periodically through an ordered set of policies; an immediate prune is a different mechanism. The configuration path depends on the driver, so a setting in the Docker daemon is not automatically the setting used by every BuildKit instance. [3]
Begin with the workload's retention requirement. Which records are expensive to regenerate? Which are disposable checkout or local-source data? How much headroom does a representative build require at its peak? The last question needs measurement on the real workload. This article provides no invented peak-disk figure or universal cache budget.
Capture the before-and-after cache distribution, then choose the smallest retention change that addresses the observed growth. Review it against a representative rebuild, including a cold-cache path when that path matters. A policy that keeps the disk below a threshold but makes every deployment miss its operating window may solve the wrong problem.
Keep cache retention separate from image rollback retention. Likewise, preserve dependency and artifact provenance when clearing cache forces downloads again. Our multi-stage build guide addresses what belongs in the runtime image; the runtime boundary and the builder's storage policy are related costs, not interchangeable controls.
Do not use periodic broad pruning to conceal an unidentified growth source. If the same incident returns before the next planned cleanup, compare the growth of the selected builder with the rest of the affected filesystem. The observation should determine whether to change cache policy, build behavior, capacity or another resource owner's retention procedure.
Mount layout is another reason to preserve the original failing path. A build step or development container can write into a mounted dependency directory whose lifetime differs from the image layer the operator is inspecting. Our node_modules mount guide follows that storage distinction. Verify that it applies to the failing operation before adding mount cleanup to a cache incident.
Close the incident with a storage evidence record#
The handoff should connect the failed build to the inspection and the mutation. Record the original command, context, named builder, driver, endpoint, relevant filesystem, selected cache filter and any approved deletion scope. Add the post-cleanup observations and the result of retrying the failed stage. Keep illustrative command output out of the real incident record.
For the fictional two-builder case, the decisive correction is selecting the store actually used by the release job. The record must show that selection explicitly. If the default builder was also pruned during diagnosis, record that separately; its changed cache accounting should not be presented as the evidence that repaired the release builder.
The examples here can be checked for shell syntax and installed CLI option support without deleting a real cache. Those checks are useful but limited. They do not establish filesystem reclamation, a safe retention interval or successful rebuilding. Make that boundary visible when moving from a written runbook to an operational change.
What else should you check?#
- Is build cache the same as the final image?
- No. Build cache retains reusable build work, while images are separately referenced artifacts. Their underlying storage can be shared. Inspect the relevant accounting and references before assuming that deleting a cache record releases all bytes associated with it. [1][5]
- Can I use a cleanup command copied from current documentation?
- Check the installed Buildx version and its help output first. Confirm the selected builder and the exact meaning of each flag. An unavailable option or a different driver can change what the written command actually does in your environment. [2]
- Does a successful prune prove the release build is fixed?
- It proves that the requested prune operation completed, within the command’s semantics. Verify the affected filesystem and retry the originally failing stage. A successful unrelated build or a smaller cache total does not establish that the release has enough working space.
- Should cache cleanup run before every build?
- Only if that retention choice fits the workload. Frequent pruning can discard expensive reusable work and conceal an unidentified growth source. Prefer a measured cache policy at the actual builder, and verify cold-build behavior and available headroom before automating it. [3]