Difficulty: Intermediate
How do you list only dangling (untagged) images, and how are they different from unused images?
Run docker images -f dangling=true (the same as docker image ls --filter dangling=true). A dangling image is one with no tag and no repository, shown as <none>:<none>, that no tagged image depends on. They pile up when you rebuild an image with the same tag: the new build takes the tag and the old one is left nameless.
Say you build myapp:dev twenty times while developing. Each build produces a new image ID. The tag myapp:dev moves to the newest ID, and the previous one keeps its layers but loses its name. It is no longer reachable by any tag, so it is dangling. Pulling a newer version of a tag (docker pull postgres:16) does the same to the old copy.
| Term | Meaning | Removed by |
|---|---|---|
| Dangling | Untagged and not a parent of a tagged image | docker image prune |
| Unused | Not used by any container, tagged or not | docker image prune -a |
Intermediate (docker images -a) | Untagged parents from the legacy builder's layer cache | Removed with their child image |
The distinction matters: docker image prune -a also deletes tagged images like node:20-alpine that no container is using right now, so the next build pulls them again. On a CI runner that is a cache wipe; on a laptop with a slow connection, it is an annoying re-download. Plain docker image prune only targets dangling images and is almost always safe.
With BuildKit (the default builder since Docker Engine 23.0), build steps go to a separate build cache rather than intermediate images, which is cleaned with docker builder prune.
--filter reference='myorg/api:*': images matching a name or tag pattern.--filter before=myapp:1.0 / --filter since=myapp:1.0: images created before or after another image.--filter label=team=payments: images with a label, useful when many teams share a build host.-q: print only IDs, ready for piping into docker rmi.--format "{{.Repository}}:{{.Tag}} {{.Size}}": custom columns.docker system df shows how much space images, containers, volumes and build cache use, and how much is reclaimable. Run it first so you know whether dangling images or the build cache is the real problem. On build servers, a scheduled docker image prune -f --filter "until=72h" keeps disk usage stable without throwing away images that the current day's jobs need.
# List dangling images
docker images -f dangling=true
# Just the IDs (handy for counting or piping)
docker images -f dangling=true -q | wc -l
# See how much space is reclaimable overall
docker system df
# Remove dangling images (safe)
docker image prune -f
# Only those older than 3 days, for a CI cron job
docker image prune -f --filter "until=72h"
Both rows are older builds of an image whose tag has since moved to a newer build. docker image prune removes them without touching tagged images.
Dangling images, docker images --filter, docker image prune, Image tags, docker system df