How do you clean up Docker disk space?
docker system prune — Cleanup
docker system prune removes stopped containers, dangling images, unused networks and the build cache after a confirmation prompt. Add -a to also remove images that no container references.
prune commands only remove what nothing references: stopped containers, dangling images, unused networks, and the build cache. The -a flag on image prune widens that to any image no container uses, which reclaims far more but means the next docker run re-downloads.
Before pruning, docker system df shows where the space actually went - images, containers, volumes, and build cache are listed separately. Volumes are excluded from system prune unless you add --volumes, precisely because that is where databases keep their data.
Related Docker shortcuts: System
| Shortcut | Action | Notes |
|---|---|---|
| docker system prune | Cleanup | Remove unused containers, images, and networks. |
| docker volume ls | List volumes | List Docker volumes. |
| docker network ls | List networks | List Docker networks. |
| docker stats | Resource usage | Show real-time CPU and memory usage per container. |
From the Docker reference (24 entries) · all how-to answers
What prune actually removes
docker system prune deletes four things: containers that have exited, networks no container uses, dangling images (layers no tag points at), and the build cache. It does not touch running containers, tagged images or named volumes, which is why a machine can still be nearly full afterwards. Adding -a widens the image rule to every image not used by a running container, and --volumes includes anonymous volumes; both are the flags that reclaim tens of gigabytes, and both delete things you may have wanted to keep.
Finding where the space went first
docker system df breaks usage into images, containers, local volumes and build cache with a reclaimable column, and docker system df -v lists them individually. Run it before pruning so the decision is informed: a large build cache means a Dockerfile that invalidates early layers, and dozens of dangling images mean repeated rebuilds of the same tag. On Docker Desktop, the VM disk image does not shrink automatically after a prune; the setting to reclaim it is in Resources.
Safer alternatives
If a full prune is too blunt, the targeted commands are docker image prune, docker container prune, docker volume prune and docker builder prune, each with the same confirmation. The --filter until=24h option on image and container prune limits removal to things older than a day, which suits a CI runner where the newest layers are about to be reused. Scheduling a filtered prune weekly is the usual fix for hosts that fill up every month.