Docker Prune
Docker prune is a family of commands that delete unused Docker objects: stopped containers, dangling images, unused networks, build cache, and optionally volumes. It reclaims disk space, but volume pruning can permanently delete data.
What each prune removes
Docker never cleans up automatically, so stopped containers, old image layers, and cache accumulate, especially on CI and build hosts. Check usage first, then prune the narrowest category that solves the problem.
docker system df # usage by type, with reclaimable spacedocker system df -v # per image, container, and volumeCommands
docker container prune # stopped containersdocker image prune # dangling images onlydocker image prune -a # all images not used by any containerdocker network prune # unused networksdocker builder prune # build cachedocker volume prune # unused volumes: data loss riskdocker system prune # containers, networks, dangling images, build cachedocker system prune --volumes # also volumes: dangerousIn Docker Engine 23.0 and later, docker volume prune removes only anonymous volumes unless you add --all.
Safe patterns
docker image prune -a --filter "until=48h" -f# crontab on a build host, 3am daily0 3 * * * docker container prune -f && docker image prune -f && docker builder prune -f --filter until=72hRisk levels
- Low: stopped containers, dangling images, unused networks, old build cache.
- Medium:
image prune -a, since the next pull re-downloads images. - High: any volume pruning, because a stopped database container leaves its volume "unused".
Common MistakeRunning
docker system prune -a --volumeswhile a database container is stopped for maintenance. Its volume counts as unused and is deleted.
TipRun
docker system dffirst and prune by category with age filters on shared hosts.
Frequently Asked Questions
Why do Docker hosts fill up with unused data?
Docker keeps stopped containers, replaced image layers, unused networks, and build cache until removed. Frequent CI builds can fill a disk within days without scheduled pruning.
Is docker system prune safe to run?
The default form is fairly safe, but it removes stopped containers and build cache and may slow the next builds. Adding -a or --volumes increases risk. Always review docker system df and avoid volumes unless you are sure.
How do I prune only old items?
Use filters, for example docker image prune -a --filter until=48h or docker builder prune --filter until=72h, which remove only items older than the given age.