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

CommandRemovesKeeps
docker system pruneStopped containers, unused networks, dangling images (untagged <none> layers), unused build cacheTagged images, all volumes
docker system prune -aAll of the above plus every image not used by a container, running or stoppedVolumes; images of existing containers
docker system prune --volumesAlso anonymous volumes no container usesNamed volumes (Docker 23 and later)
docker builder pruneUnused build cache only; -a for all of itImages, containers
docker image prune -a --filter "until=168h"Unused images older than a weekRecent ones
docker volume prune -aEvery volume no container uses, named ones tooVolumes 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

4. Keep it from coming back

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 .

Try it

Related guides

Newest guides