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.
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><none>:<none></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.
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 thelatesttag 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.
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=trueshows only dangling images. - IDs only: add
-qfor scripting. - Disk summary:
docker system dfreports 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.
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 pruneasks for confirmation and removes dangling images. Add-fin scripts. - Everything unused:
docker image prune -aalso 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 pruneremoves stopped containers, unused networks, dangling images and build cache. Volumes are removed only with--volumes. - Seeing the parents:
docker images -aadditionally lists intermediate images on the classic builder. With BuildKit these are hidden, so an empty dangling list does not mean the disk is clean.
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. Checkdocker images --digestsand 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=trueanddocker system dfto 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.
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
latestand leaves orphans. - Scheduled cleanup: run
docker image prune -f --filter until=168hfrom cron or a systemd timer on build agents. - Alert on disk: monitor
/var/lib/dockerusage 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.
- A dangling image is untagged and unreferenced, shown as <code><none>:<none></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.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- 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.
- Running docker system prune --volumes casually It deletes unused volumes, which can contain database files and cannot be recovered.
- 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.
- 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.