Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 18/ 160
01. Containerization & Docker Fundamentals

Pruning Unused Containers, Images & Disk Space (docker system prune)

Reclaim disk safely with prune commands without deleting volumes you still need.

Beginnerprune · Disk Space3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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 --force for 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

Loading interactive 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.

Concrete prune setup

docker system df -v && docker system prune --all --filter until=168h --force

Key takeaway: Prove Disk Space with 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.

Deliberate failure test

Exercise this failure safely: adding --volumes by habit, running prune on a host without an ownership inventory, or assuming unused means no longer valuable.

Key takeaway: Regular filtered pruning trades a small amount of stale cache for predictability; keeping everything gives faster rebuilds but invites disk-full outages.

How it works, step by step

Step 1 of 4
Design

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

Prune only the classes you have inventoried, using age or label filters, after measuring what is reclaimable.
Key numbers at this step
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 totals in 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

Explicit prune
Best for: Reclaim disk safely with prune commands without deleting volumes you still need, with a reviewed runbook.

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.

Ambient default
Best for: Short-lived Disk Space experiments with low blast radius.

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.

Managed Dangling
Best for: Teams that centralize Dangling policy across many workloads.

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 --force as proof and skipping re-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 --force address 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?
Interview tip: Give one concrete operation-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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Monitoring Container Events & Resource Usage (top, events, diff)
Next topic
Linux Kernel Primitives: Namespaces (PID, NET, MNT, UTS, IPC)