capabilities.work

Reclaim Disk Space on a Host

A 7-step recipe with Docker. We can help you get access.

Recipe · 7 steps

Reclaim Disk Space on a Host

with Docker

Measure, prune in dependency order, and re-measure host disk usage.

  1. Take a before reading across all four object types so the reclaim can be quantified rather than guessed at.
  2. Prune stopped containers older than the age filter first. This must precede the image prune, because an image still referenced by a stopped container cannot be removed.
  3. Prune only dangling — unused and untagged — images. Setting dangling to false would remove every unused image, including tagged ones a pipeline expects to still be cached.
  4. Prune unused volumes, scoped by the supplied label filter. This is the destructive step in the flow — a volume prune without a filter will take any unused named volume with it, data and all.
  5. Prune user-defined networks with no attached containers, older than the age filter. Pre-defined networks are never touched by this call.
  6. Trim the BuildKit cache down to a reserved size rather than clearing it outright, so subsequent builds keep most of their cache hits.
  7. Take the after reading across the same four object types so the caller can diff it against the before reading and report what was actually reclaimed.
What you'll need to have ready
  • until: Age filter applied to container, image, and network prunes, e.g. "24h" or "168h".
  • pruneVolumes: Whether to prune unused volumes. Off by default because volume prunes destroy data.
  • volumeFilters: JSON-encoded volume prune filters, e.g. {"label":["ci-scratch"]}. Scope this narrowly.
  • buildCacheReservedSpace: Bytes of build cache to keep when pruning the builder cache.
For your developer

Arazzo workflow docker:reclaim-disk-space, 7 operations: SystemDataUsage → ContainerPrune → ImagePrune → VolumePrune → NetworkPrune → BuildPrune → SystemDataUsage. Specs on APIs.io.