Docker eating your disk: what docker system prune deletes and how to reclaim space safely
Docker keeps everything until you tell it not to: every image you pulled, every layer you built, stopped containers, build cache and container logs. On a laptop or a small server that adds up to tens of gigabytes. Pruning is safe once you know which command removes what.
1. Look first
docker system df # images, containers, local volumes, build cache
docker system df -v # the same, item by item
The RECLAIMABLE column is what pruning could free. Build cache is often the biggest surprise.
2. What each command deletes
| Command | Removes | Keeps |
|---|---|---|
docker system prune | Stopped containers, unused networks, dangling images (untagged <none> layers), unused build cache | Tagged images, all volumes |
docker system prune -a | All of the above plus every image not used by a container, running or stopped | Volumes; images of existing containers |
docker system prune --volumes | Also anonymous volumes no container uses | Named volumes (Docker 23 and later) |
docker builder prune | Unused build cache only; -a for all of it | Images, containers |
docker image prune -a --filter "until=168h" | Unused images older than a week | Recent ones |
docker volume prune -a | Every volume no container uses, named ones too | Volumes in use |
Volumes are where databases keep their data. A stopped Postgres container plus docker system prune --volumes can be enough to lose a development database, so list them first with docker volume ls.
3. The space that prune doesn’t find
- Container logs. The default json-file driver never rotates. Check with
sudo du -sh /var/lib/docker/containers/*/*-json.log. Limit them in/etc/docker/daemon.jsonwith{"log-driver":"json-file","log-opts":{"max-size":"10m","max-file":"3"}}, restart Docker, and recreate the containers (it applies to new ones). - Docker Desktop on Mac and Windows. Everything lives inside one virtual disk file that grows but doesn’t always shrink straight away. After pruning, check the disk usage limit under Settings, Resources; “Clean / Purge data” in Troubleshoot wipes everything.
- Running containers writing inside themselves.
docker ps -sshows each container’s own writable size; a big one is usually writing logs or uploads that belong in a volume.
4. Keep it from coming back
- Use
docker compose downrather than leaving stopped stacks around, anddocker run --rmfor one-off containers. - Smaller builds: a
.dockerignore(skipnode_modules,.git, build output), multi-stage builds, and fewer copies of the same base image. - On build servers, a nightly
docker system prune -af --filter "until=72h". The cron explainer checks the schedule line.
Related
The disk already full and every command failing with no space left on device? Start with ENOSPC: no space left on device. Can’t run docker without sudo: docker.sock permission denied. Builds getting killed rather than running out of disk: exit code 137.
Questions
Is docker system prune safe?
Yes for most setups: it only removes stopped containers, unused networks, dangling images and unused build cache, and it never removes volumes unless you add --volumes.
What is the difference between docker system prune and docker system prune -a?
Without -a only dangling (untagged) images are removed. With -a every image not used by any container is removed too, so you will download or rebuild them next time.
Does docker system prune delete volumes?
No. Only with --volumes, and then only unused anonymous volumes on Docker 23 and later. docker volume prune -a also removes unused named volumes.
Why is Docker still using space after pruning?
Common culprits are container log files, which prune does not touch, running containers writing inside themselves, and Docker Desktop's virtual disk, which may not shrink straight away.
Published .