⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Docker & Containers Interview Questions Scenario 41 of 159 in Docker & Containers
Senior DevOps / SRE [L2] Docker Production Scenario [L2]
🎯 Target Role / Context: Docker Scenario #41 (L2) · Docker

Q: What is a "dangling image" in Docker?

A dangling image in Docker is an image with no tag and no remaining reference from a tagged image, shown as none:none in docker images.

#Docker #L2 #Containers #Linux
🎙️ Candidate Opening & Architectural Context
"A <strong>dangling image in Docker</strong> is an image with no tag and no remaining reference from a tagged image, shown as <code>&lt;none&gt;:&lt;none&gt;</code> in <code>docker images</code>. It typically appears when you rebuild an image under the same tag: the tag moves to the new build and the previous one is left untagged. Interviewers ask this to see whether you can reclaim disk space on build hosts without deleting images that are still needed. The key distinction is dangling versus unused, and knowing which prune command removes which."
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's Docker Certified Associate (DCA) Hands-On Lab Course covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: A <strong>dangling image in Docker</strong> is an image with no tag and no remaining reference from a tagged image, shown as <code>&lt;none&gt;:&lt;none&gt;</code> in <code>docker images</code>. It typically appears when you rebuild an image under the same tag: the tag moves to the new build and the previous one is left untagged. Interviewers ask this to see whether you can reclaim disk space on build hosts without deleting images that are still needed. The key distinction is dangling versus unused, and knowing which prune command removes which.

1️⃣

Mental model: how an image becomes dangling

Tags are movable pointers to image IDs. When a tag moves, the old image keeps existing but loses its name. Cleaning too aggressively on a shared host can slow the next build because cached images must be pulled again.

  • Cause: docker build -t my-app:latest . run twice. The second build takes the latest tag and the first becomes dangling. Pulling a newer image for the same tag does the same.
  • Dangling: untagged and not a parent layer of any tagged image.
  • Unused: a tagged image that no container currently references. Not dangling, and removed only with prune -a.
  • Not the same as build cache: BuildKit cache is separate and is cleaned with docker builder prune.
  • Why they accumulate: CI agents that rebuild the same tag on every commit create one dangling image per build, so a busy runner can collect dozens of them in a day, each holding its own layers.
2️⃣

Hands-on: find a dangling image in Docker

List them with a filter and see how much space is involved.

docker images -f dangling=true
# REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
# <none>       <none>    3f2a9c1b7d44   2 hours ago    187MB

docker images -f dangling=true -q
docker system df
  • Filter: docker images -f dangling=true shows only dangling images.
  • IDs only: add -q for scripting.
  • Disk summary: docker system df reports reclaimable space for images, containers, volumes and build cache.
  • Reproduce one: build the same tag twice with a changed file and watch the first image turn into <none>.
  • Shared layers: deleting a dangling image only frees the layers that no other image uses. The reclaimed space is often smaller than the listed sizes added together.
Advertisement
3️⃣

Remove dangling images safely

Use the narrowest command that does the job.

docker image prune                          # dangling only, prompts
docker image prune -f --filter "until=168h" # older than 7 days, no prompt
docker image prune -a --filter "until=720h" # all unused older than 30 days

docker builder prune --filter until=168h    # BuildKit cache
docker system df                            # confirm space reclaimed
  • Dangling only: docker image prune asks for confirmation and removes dangling images. Add -f in scripts.
  • Everything unused: docker image prune -a also removes tagged images with no container. Be careful on hosts that rely on pre-pulled images.
  • Age filter: --filter "until=168h" keeps anything newer than seven days.
  • Whole system: docker system prune removes stopped containers, unused networks, dangling images and build cache. Volumes are removed only with --volumes.
  • Seeing the parents: docker images -a additionally lists intermediate images on the classic builder. With BuildKit these are hidden, so an empty dangling list does not mean the disk is clean.
Pro Tip: <code>docker system prune --volumes</code> deletes unused volumes, which may contain data you need. Never run it on a host with database volumes unless you have a backup.
4️⃣

Edge cases and verification

Not everything labelled none is safe to delete blindly. Check each symptom against the evidence before changing anything.

  • Images pulled by digest: they can show <none> as the tag and still be in use. Check docker images --digests and running containers before removing manually.
  • In-use images are protected: removal of an image used by a container fails. Remove the container first.
  • Intermediate layers: with BuildKit, intermediate build steps do not appear as dangling images. They live in the build cache.
  • Verify: rerun docker images -f dangling=true and docker system df to confirm the reclaimable figure dropped.
  • Inspecting before deleting: docker image inspect <id> shows creation time, labels and the original command, which helps decide whether an untagged image is worth keeping for a rollback.
5️⃣

Production practice: stop dangling images piling up

Treat cleanup as scheduled housekeeping and reduce how many are created.

  • Tag builds uniquely: use commit SHA or version tags so nothing silently overwrites latest and leaves orphans.
  • Scheduled cleanup: run docker image prune -f --filter until=168h from cron or a systemd timer on build agents.
  • Alert on disk: monitor /var/lib/docker usage so a full disk does not break builds.
  • Registry side: apply registry retention policies, because local pruning does not clean remote repositories.
  • Registry parity: pushing to a registry does not create dangling images remotely, but untagged manifests can remain there, and registry garbage collection is a separate job.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: <code>docker image prune</code> removes only dangling images, while <code>-a</code> removes every unused image. On shared build hosts add an <code>until</code> filter so you do not delete images someone just pulled."
⚡ 60-Second Elevator Pitch Talking Points
  • A dangling image is untagged and unreferenced, shown as <code>&lt;none&gt;:&lt;none&gt;</code>, usually left behind when a rebuild moves a tag.
  • I list them with <code>docker images -f dangling=true</code> and check reclaimable space with <code>docker system df</code>.
  • I automate <code>docker image prune</code> with an age filter and use unique tags so rebuilds do not create orphans.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Confusing dangling with unused Dangling means untagged. A tagged image that no container uses is only removed by prune -a, which may delete images you wanted cached.
  2. Running docker system prune --volumes casually It deletes unused volumes, which can contain database files and cannot be recovered.
  3. Ignoring BuildKit cache when disk fills up Dangling images are only part of the picture. Build cache can be large and needs docker builder prune.
  4. Deleting every none image by ID in a script Some untagged images are referenced by digest or by other images, and removal can fail or break deployments.
Advertisement
Want more Docker & Containers scenarios?
Explore our complete collection of scenario-based Docker & Containers interview runbooks.
Browse All Docker & Containers Questions →