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 57/ 160
03. Storage, Volumes & Data Persistence

Cleaning Up Dangling & Orphaned Volumes

Find and remove unused volumes without deleting data still attached to services.

BeginnerDangling · volume prune3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Prove ownership and backup status before removing a data object that no current manifest references.

Think of it like…

An unlabeled suitcase in lost property is not automatically trash; it may be luggage from a delayed traveller who still holds the only receipt.

Where you’ve seen it

In practice, docker volume ls --filter dangling=true --format {{.Name}}; docker volume inspect candidate; docker volume prune --filter label=retention=dev-only is the concrete move for this job: find and remove unused volumes without deleting data still attached to services. The release is not accepted until label owners first, back up candidates, then dry-run the intended selector with docker volume ls and a documented retention window confirms the result.

Words you’ll hear

Dangling
The implementation control in docker volume ls --filter dangling=true --format {{.Name}}; docker volume inspect candidate; docker volume prune --filter label=retention=dev-only for find and remove unused volumes without deleting data still attached to services.
volume prune
The result to observe with label owners first, back up candidates, then dry-run the intended selector with docker volume ls and a documented retention window, rather than infer from a successful command alone.
Safety
The production boundary exposed when using --all on a prune command without checking protected labels or an external restore catalog.

Visual diagram

Loading interactive diagram

Theory & deep dive

Dangling control path

The concrete mechanism is docker volume ls --filter dangling=true --format {{.Name}}; docker volume inspect candidate; docker volume prune --filter label=retention=dev-only. The observable result is label owners first, back up candidates, then dry-run the intended selector with docker volume ls and a documented retention window; if those disagree, inspect the runtime evidence before changing unrelated settings.

Find and remove unused volumes without deleting data still attached to services. Keep Dangling, volume prune and Safety in the same deployment record so the intent and the observed state cannot drift apart.

Concrete Dangling setup

docker volume ls --filter dangling=true --format {{.Name}}; docker volume inspect candidate; docker volume prune --filter label=retention=dev-only

Key takeaway: Prove volume prune with label owners first, back up candidates, then dry-run the intended selector with docker volume ls and a documented retention window, not with command success alone.

Safety failure boundary

A deploy pause or missing compose project temporarily detaches healthy data. Pruning based only on “not attached” can destroy the easiest rollback path and any recovery data that was not restored into a running service. The narrow failure to design for is using --all on a prune command without checking protected labels or an external restore catalog.

Accept this compromise explicitly: Manual review is safer for production volumes; policy-labeled automatic pruning is efficient for clearly disposable CI data. The controlled check-label owners first, back up candidates, then dry-run the intended selector with docker volume ls and a documented retention window-also identifies the point where a different design is safer.

Deliberate failure test

Exercise this failure safely: using --all on a prune command without checking protected labels or an external restore catalog.

Key takeaway: Manual review is safer for production volumes; policy-labeled automatic pruning is efficient for clearly disposable CI data.

How it works, step by step

Step 1 of 4
Design

1. State the boundary

Write down why the workload needs this: A deploy pause or missing compose project temporarily detaches healthy data. Pruning based only on “not attached” can destroy the easiest rollback path and any recovery data that was not restored into a running service.

Prove ownership and backup status before removing a data object that no current manifest references.
Key numbers at this step
Intent
Dangling

When to use it & trade-offs

What it is

Dangling volume means the volume currently has no container reference; it does not mean the data is unneeded. docker volume prune filters by age or label and asks Docker to remove those unreferenced local objects, while an orphan from an old compose project can still carry recoverable databases.

Why it matters: A deploy pause or missing compose project temporarily detaches healthy data. Pruning based only on “not attached” can destroy the easiest rollback path and any recovery data that was not restored into a running service.

When to reach for it

  • The fit is strongest for this job: find and remove unused volumes without deleting data still attached to services. Pair it with label owners first, back up candidates, then dry-run the intended selector with docker volume ls and a documented retention window in the runbook.
  • Production Dangling changes should make volume prune observable through docker volume ls --filter dangling=true --format {{.Name}}; docker volume inspect candidate; docker volume prune --filter label=retention=dev-only, rather than trusting the runtime default.
  • Keep a rollback example for the case where using --all on a prune command without checking protected labels or an external restore catalog.

When to avoid or be careful

  • Do not accept command success while the system can still fail by using --all on a prune command without checking protected labels or an external restore catalog.
  • Avoid erasing Safety protection merely to dodge this cost: “Manual review is safer for production volumes; policy-labeled automatic pruning is efficient for clearly disposable CI data”.
  • Do not replace the evidence path-label owners first, back up candidates, then dry-run the intended selector with docker volume ls and a documented retention window-with a screenshot or a mutable tag.

docker volume ls --filter dangling=true --format {{.Name}}; docker volume inspect candidate; docker volume prune --filter label=retention=dev-only: practical choices

Explicit Dangling
Best for: Find and remove unused volumes without deleting data still attached to services, with a reviewed runbook.

Strengths: Dangling volume means the volume currently has no container reference; it does not mean the data is unneeded. docker volume prune filters by age or label and asks Docker to remove those unreferenced local objects, while an orphan from an old compose project can still carry recoverable databases.

Watch out: Manual review is safer for production volumes; policy-labeled automatic pruning is efficient for clearly disposable CI data.

Ambient default
Best for: Short-lived volume prune experiments with low blast radius.

Strengths: It can begin with docker volume ls --filter dangling=true --format {{.Name}}; docker volume inspect candidate; docker volume prune --filter label=retention=dev-only and fewer surrounding controls.

Watch out: It silently accepts using --all on a prune command without checking protected labels or an external restore catalog, which makes the result hard to reproduce after promotion.

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

Strengths: A deploy pause or missing compose project temporarily detaches healthy data. Pruning based only on “not attached” can destroy the easiest rollback path and any recovery data that was not restored into a running service.

Watch out: The platform adds an ownership and debugging layer; retain label owners first, back up candidates, then dry-run the intended selector with docker volume ls and a documented retention window as the direct check.

Interview signals & numbers to know

When this topic comes up

  • docker volume ls --filter dangling=true --format {{.Name}}; docker volume inspect candidate; docker volume prune --filter label=retention=dev-only
  • label owners first, back up candidates, then dry-run the intended selector with docker volume ls and a documented retention window
  • Failure signature: using --all on a prune command without checking protected labels or an external restore catalog
  • Trade-off: Manual review is safer for production volumes; policy-labeled automatic pruning is efficient for clearly disposable CI data.

Benchmarks & rules of thumb

1 zero-reference test -
defines dangling, not business value
2 safeguards -
labels and backups before removal
0 active mounts -
required for prune candidates

Common mistakes & follow-ups

Common interview mistakes

  • Treating a successful docker volume ls --filter dangling=true --format {{.Name}}; docker volume inspect candidate; docker volume prune --filter label=retention=dev-only as proof and skipping label owners first, back up candidates, then dry-run the intended selector with docker volume ls and a documented retention window.
  • Using --all on a prune command without checking protected labels or an external restore catalog
  • Optimizing Dangling without accepting that manual review is safer for production volumes; policy-labeled automatic pruning is efficient for clearly disposable CI data.

Likely interviewer follow-ups

  • Why does docker volume ls --filter dangling=true --format {{.Name}}; docker volume inspect candidate; docker volume prune --filter label=retention=dev-only address Dangling here rather than through application code?
  • How would you distinguish healthy volume prune from the failure “using --all on a prune command without checking protected labels or an external restore catalog” using label owners first, back up candidates, then dry-run the intended selector with docker volume ls and a documented retention window?
  • When would this trade-off-“Manual review is safer for production volumes; policy-labeled automatic pruning is efficient for clearly disposable CI data”-justify a different Safety design?
Interview tip: Give one concrete operation-docker volume ls --filter dangling=true --format {{.Name}}; docker volume inspect candidate; docker volume prune --filter label=retention=dev-only-and one proof-label owners first, back up candidates, then dry-run the intended selector with docker volume ls and a documented retention window. Then name the boundary: using --all on a prune command without checking protected labels or an external restore catalog.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Cleaning Up Dangling & Orphaned Volumes with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Inspecting Storage Usage (docker system df)
Next topic
Populating Empty Volumes from Container Directories