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 df

This 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 ls first.
  • An important container is gone: prune only removes stopped containers. Manage containers with Docker Compose so restarting them is easy.

Summary table

CommandWhat it removesData risk
docker system pruneStopped containers, unused networks, dangling images, build cacheLow, volumes safe
docker system prune -fSame, without confirmationLow, only once the command is reviewed
docker system prune -aPlus all unused imagesMedium, re-pull needed
docker system prune --volumesPlus unused anonymous volumesHigh if not checked first
docker volume prune --allAll unused volumes, including named onesVery high, back up first

Final checklist

  • docker system df run before and after pruning.
  • docker volume ls checked before using --volumes.
  • No running container disturbed.
  • Free space increased by the Total reclaimed space amount.

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