Pruning Unused Containers, Images & Disk Space (docker system prune)
Reclaim disk safely with prune commands without deleting volumes you still need.
In plain words
Prune only the classes you have inventoried, using age or label filters, after measuring what is reclaimable.
Think of it like…
Cleaning a workshop is routine until you put the unlabeled parts cabinet and archived blueprints in the same dumpster.
Where you’ve seen it
In practice, docker system df -v && docker system prune --all --filter until=168h --force is the concrete move for this job: reclaim disk safely with prune commands without deleting volumes you still need. The release is not accepted until re-run docker system df after recording image, container, cache and volume totals confirms the result.
Words you’ll hear
- prune
- The implementation control in
docker system df -v && docker system prune --all --filter until=168h --forcefor reclaim disk safely with prune commands without deleting volumes you still need. - Disk Space
- The result to observe with
re-run docker system df after recording image, container, cache and volume totals, rather than infer from a successful command alone. - Dangling
- The production boundary exposed when adding --volumes by habit, running prune on a host without an ownership inventory, or assuming unused means no longer valuable.
Visual diagram
Theory & deep dive
prune control path
The concrete mechanism is docker system df -v && docker system prune --all --filter until=168h --force. The observable result is re-run docker system df after recording image, container, cache and volume totals; if those disagree, inspect the runtime evidence before changing unrelated settings.
Reclaim disk safely with prune commands without deleting volumes you still need. Keep prune, Disk Space and Dangling in the same deployment record so the intent and the observed state cannot drift apart.
docker system df -v && docker system prune --all --filter until=168h --force
re-run docker system df after recording image, container, cache and volume totals, not with command success alone.Dangling failure boundary
Shared CI workers often fail from disk pressure, but a rushed system prune can delete a stopped rollback container or a data volume a later compose project expects. Ordinary prune and volume prune have very different recovery consequences. The narrow failure to design for is adding --volumes by habit, running prune on a host without an ownership inventory, or assuming unused means no longer valuable.
Accept this compromise explicitly: Regular filtered pruning trades a small amount of stale cache for predictability; keeping everything gives faster rebuilds but invites disk-full outages. The controlled check-re-run docker system df after recording image, container, cache and volume totals-also identifies the point where a different design is safer.
Exercise this failure safely: adding --volumes by habit, running prune on a host without an ownership inventory, or assuming unused means no longer valuable.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: Shared CI workers often fail from disk pressure, but a rushed system prune can delete a stopped rollback container or a data volume a later compose project expects. Ordinary prune and volume prune have very different recovery consequences.
- Intent
- prune
When to use it & trade-offs
What it is
docker system prune removes stopped containers, unused networks, dangling images and build cache; -a also removes images with no container reference. Volumes are intentionally excluded unless --volumes is added, which should be treated as destructive data cleanup.
Why it matters: Shared CI workers often fail from disk pressure, but a rushed system prune can delete a stopped rollback container or a data volume a later compose project expects. Ordinary prune and volume prune have very different recovery consequences.
When to reach for it
- The fit is strongest for this job: reclaim disk safely with prune commands without deleting volumes you still need. Pair it with
re-run docker system df after recording image, container, cache and volume totalsin the runbook. - Production prune changes should make Disk Space observable through
docker system df -v && docker system prune --all --filter until=168h --force, rather than trusting the runtime default. - Keep a rollback example for the case where adding --volumes by habit, running prune on a host without an ownership inventory, or assuming unused means no longer valuable.
When to avoid or be careful
- Do not accept command success while the system can still fail by adding --volumes by habit, running prune on a host without an ownership inventory, or assuming unused means no longer valuable.
- Avoid erasing Dangling protection merely to dodge this cost: “Regular filtered pruning trades a small amount of stale cache for predictability; keeping everything gives faster rebuilds but invites disk-full outages”.
- Do not replace the evidence path-
re-run docker system df after recording image, container, cache and volume totals-with a screenshot or a mutable tag.
docker system df -v && docker system prune --all --filter until=168h --force: practical choices
Strengths: docker system prune removes stopped containers, unused networks, dangling images and build cache; -a also removes images with no container reference. Volumes are intentionally excluded unless --volumes is added, which should be treated as destructive data cleanup.
Watch out: Regular filtered pruning trades a small amount of stale cache for predictability; keeping everything gives faster rebuilds but invites disk-full outages.
Strengths: It can begin with docker system df -v && docker system prune --all --filter until=168h --force and fewer surrounding controls.
Watch out: It silently accepts adding --volumes by habit, running prune on a host without an ownership inventory, or assuming unused means no longer valuable, which makes the result hard to reproduce after promotion.
Strengths: Shared CI workers often fail from disk pressure, but a rushed system prune can delete a stopped rollback container or a data volume a later compose project expects. Ordinary prune and volume prune have very different recovery consequences.
Watch out: The platform adds an ownership and debugging layer; retain re-run docker system df after recording image, container, cache and volume totals as the direct check.
Interview signals & numbers to know
When this topic comes up
- docker system df -v && docker system prune --all --filter until=168h --force
- re-run docker system df after recording image, container, cache and volume totals
- Failure signature: adding --volumes by habit, running prune on a host without an ownership inventory, or assuming unused means no longer valuable
- Trade-off: Regular filtered pruning trades a small amount of stale cache for predictability; keeping everything gives faster rebuilds but invites disk-full outages.
Benchmarks & rules of thumb
- 168 hours
- seven-day age filter in the example
- 0 volumes
- included by system prune unless --volumes is explicit
- 2 object classes
- unused networks and build cache often surprise operators
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
docker system df -v && docker system prune --all --filter until=168h --forceas proof and skippingre-run docker system df after recording image, container, cache and volume totals. - Adding --volumes by habit, running prune on a host without an ownership inventory, or assuming unused means no longer valuable
- Optimizing prune without accepting that regular filtered pruning trades a small amount of stale cache for predictability; keeping everything gives faster rebuilds but invites disk-full outages.
Likely interviewer follow-ups
- Why does
docker system df -v && docker system prune --all --filter until=168h --forceaddress prune here rather than through application code? - How would you distinguish healthy Disk Space from the failure “adding --volumes by habit, running prune on a host without an ownership inventory, or assuming unused means no longer valuable” using
re-run docker system df after recording image, container, cache and volume totals? - When would this trade-off-“Regular filtered pruning trades a small amount of stale cache for predictability; keeping everything gives faster rebuilds but invites disk-full outages”-justify a different Dangling design?
docker system df -v && docker system prune --all --filter until=168h --force-and one proof-re-run docker system df after recording image, container, cache and volume totals. Then name the boundary: adding --volumes by habit, running prune on a host without an ownership inventory, or assuming unused means no longer valuable.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Pruning Unused Containers, Images & Disk Space (docker system prune) with generative AI interview Q&A and hands-on practice.