$ run as a normal user# run as root (or with sudo)
The quick answer
docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 48 6 21.4GB 18.9GB (88%)
Containers 9 6 1.2GB 310MB (25%)
Local Volumes 14 5 6.8GB 2.1GB (30%)
Build Cache 212 0 9.7GB 9.7GB
docker container prune -f
docker image prune -a -f --filter "until=168h"
docker builder prune -f --filter "until=168h"These three lines remove stopped containers, images not used by any container and older than 7 days, and old build cache. They do not touch volumes.
Step by step
- See where the space goes:
docker system df -v | head -40
du -sh /var/lib/docker/* | sort -h
du -h /var/lib/docker/containers/*/*-json.log | sort -h | tail -5- Clean each part — from safe to careful:
| Command | Removes | Risk |
|---|---|---|
docker container prune | Stopped containers. | Low (their logs are gone too). |
docker image prune | Dangling images (<none> tags). | None. |
docker image prune -a | All images no container uses. | Low — they are pulled again when needed (slower next deploy). |
docker builder prune | Build cache. | Low — the next build is slower. |
docker volume prune | Unused anonymous volumes. | Medium — check first. |
docker volume prune -a | All unused volumes, also named ones. | High — data loss (databases!). |
docker system prune | Containers, networks, dangling images, cache. | Low (no volumes unless --volumes). |
- Before you delete volumes, look at them:
docker volume ls -f dangling=true
docker volume inspect shop_db-data --format '{{.Mountpoint}} {{.CreatedAt}}'A volume of a stopped database container is "unused" — but it is your data. Back it up first if in doubt.
- Big log files — empty one now, then set rotation so it does not come back:
truncate -s 0 $(docker inspect --format '{{.LogPath}}' api){
"log-driver": "json-file",
"log-opts": { "max-size": "10m", "max-file": "3" }
}- Clean automatically on build servers (weekly), with a systemd timer or cron:
0 4 * * 0 root docker system prune -af --filter "until=168h" > /var/log/docker-prune.log 2>&1- Still too small? Move Docker to a bigger disk: stop Docker, copy
/var/lib/docker(withrsync -aHAX), set"data-root": "/data/docker"indaemon.json, start Docker.
Check that it worked
Common problems
| Problem | Cause | Fix |
|---|---|---|
| Prune freed almost nothing | Images are used by stopped containers, or the space is logs. | Remove old containers first; check *-json.log sizes. |
df shows the disk still full | A running container still writes to a deleted log file. | Use truncate, not rm, for logs; restart the container. |
| A database is empty after cleanup | docker volume prune -a or --volumes removed its volume. | Restore from backup. Never use these on hosts with data without checking. |
| Disk full again after some days | No log rotation; CI builds fill the cache. | daemon.json log options; scheduled prune with until=. |
/var/lib/docker/overlay2 is huge | Image layers and container files. | Prune images; find big containers with docker ps -s. |
Go further
- Command pages: docker, df, du.
- Next how-tos: Check disk space and find what fills the disk, See the logs of a container, Schedule a job with cron.
- Learn it: Docker — Prune, Docker — Volumes, Docker — Back up volumes.
- Full guide: Install and set up Docker.
1Which prune commands can delete data?
docker volume prune (and -a) and docker system prune --volumes.