Images, stopped containers, volumes and build cache stay on disk until you remove them. Look before you delete.
Measure
docker system dfTYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 6 2 977MB 534MB (55%)
Containers 2 1 2.19kB 1.09kB (50%)
Local Volumes 4 1 143B 19B (13%)
Build Cache 15 0 104MB 104MBACTIVE means used by a container (running or stopped). RECLAIMABLE is what removing the unused ones would free. docker system df -v lists each volume with its size and number of containers using it (LINKS).
What is unused
| Thing | Unused when | How it appears |
|---|---|---|
| Container | Stopped (Exited) | docker ps -a |
| Dangling image | It has no tag, usually an old build whose tag moved | <none> <none> in docker images |
| Unused image | No container, running or stopped, uses it | A normal row in docker images |
| Anonymous volume | No container mounts it; its name is a 64-character hash | docker volume ls |
| Named volume | No container mounts it | docker volume ls |
An unused named volume may still hold the only copy of some data. Unused does not mean worthless.
Remove by rule
| Command | Removes | Keeps |
|---|---|---|
docker container prune | Stopped containers | Running containers |
docker image prune | Dangling images | Every tagged image |
docker image prune -a | Every image no container uses | Images used by any container |
docker volume prune | Unused anonymous volumes | All named volumes |
docker volume prune -a | Unused anonymous and named volumes | Volumes mounted by a container |
docker system prune | Stopped containers, unused networks, dangling images, build cache | Volumes, tagged images |
docker builder prune | Build cache | Images |
Each prune asks first. Anything except y cancels:
$ docker volume prune
WARNING! This will remove anonymous local volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Deleted Volumes:
06e0c13581597d64c00072a2cadfb81c93db74fbc486111badaec07c034a13e7
Total reclaimed space: 0B-f skips the question. Use it in scripts, not while you are still deciding.
Remove by name
When a rule would catch something you want to keep, name the objects:
docker rm migrate
docker rmi redis:7.4
docker volume rm old-cachedocker rmi on an image with several tags only untags. The image is deleted with its last tag. It refuses while any container uses the image:
Error response from daemon: conflict: unable to remove repository reference "postgres:16" (must force) - container e1dd94dc29ef is using its referenced image 7d3a5854d55cA safe order
1. docker system df measure
2. docker ps -a / images / volume ls look at what is listed
3. docker container prune stopped containers first: they hold images and volumes
4. docker image prune dangling images
5. docker rmi NAME unused tagged images you chose
6. docker volume prune anonymous volumes
7. docker volume rm NAME named volumes you are sure about
8. docker system df measure againRemoving containers first matters: a stopped container still counts as using its image and its volumes.