VPS Disk Full Because of Docker? Clean Up Safely with docker system prune
Your VPS refuses to write files and shows No space left on device, even though your apps have not grown. The culprit most people overlook is Docker: old images, stopped containers never removed, and a swelling build cache.
Before deleting anything, see where the space actually went:
docker system dfThis breaks usage down by type — Images, Containers, Local Volumes, Build Cache — with a RECLAIMABLE column showing what can be freed.
The safe prune: only unused things go
The standard command is:
docker system prune
Confirm first. It removes stopped containers, unused networks, dangling images, and build cache. Running containers are not touched, and volumes are not deleted at all.
Without a prompt, only for scripts you have already reviewed, add -f:
docker system prune -f
Expect a line reporting Total reclaimed space. Run docker system df again and compare.
The red line: --volumes and -a
docker system prune --volumes also removes unused anonymous volumes. Unused named volumes survive that command; deleting them requires docker volume prune --all, which is far riskier.
Rule: do not add --volumes before checking docker volume ls and being sure a volume is really junk. Databases, user uploads, and application state live in volumes.
The -a flag: docker system prune -a removes all unused images, not just dangling ones. Run docker images first before using -a.
Clean one piece at a time when that is all you need
Per-component commands:
docker container prune docker image prune docker network prune docker builder prune
Each cleans only its own component. An age filter limits the clean-up, for example:
docker system prune --filter "until=168h"
Schedule it so the problem does not return
Use a weekly cron job or systemd timer, for example Sunday at 03:00 via crontab -e:
0 3 * * 0 docker system prune -f
Never schedule --volumes or -a automatically without supervision.
Common mistakes
- Space barely moves: the space is probably in a named volume or in container logs — check
docker volume lsfirst. - An important container is gone: prune only removes stopped containers. Manage containers with Docker Compose so restarting them is easy.
Summary table
| Command | What it removes | Data risk |
|---|---|---|
docker system prune | Stopped containers, unused networks, dangling images, build cache | Low, volumes safe |
docker system prune -f | Same, without confirmation | Low, only once the command is reviewed |
docker system prune -a | Plus all unused images | Medium, re-pull needed |
docker system prune --volumes | Plus unused anonymous volumes | High if not checked first |
docker volume prune --all | All unused volumes, including named ones | Very high, back up first |
Final checklist
docker system dfrun before and after pruning.docker volume lschecked before using--volumes.- No running container disturbed.
- Free space increased by the
Total reclaimed spaceamount.
Which part of Docker eats the most disk on your server? Share your docker system df result in the comments.
Baca juga: Docker Compose untuk Self-Hosting dari Nol and Docker Volume dan Backup: Jangan Sampai Data Hilang.


Komentar
Posting Komentar