Docker cleanup cheat sheet: reclaim disk

Docker is generous with disk: every stopped container, every replaced image layer and every unused volume stays on disk until you remove it. The result is machines that mysteriously fill up. The fix is a small set of commands, run in order from look to delete.

The rule of thumb: start with docker system df to see what is actually using space, then prune narrowly before you prune everything. A dangling image is an untagged <none>:<none> layer left behind when a tag is reused — those are always safe to remove.

Published

See what is using space

Measure before you delete
# Summary of disk usage by category
docker system df

# Verbose: break it down per image/container/volume
docker system df -v

# Live memory/CPU per running container
docker stats --no-stream

Prune, from narrow to everything

The prune family — read the 'removes' column before running the wider ones
CommandRemoves
docker container pruneall stopped containers
docker image prunedangling images only (untagged <none>:<none>)
docker image prune -aall images not used by at least one container (keeps nothing spare)
docker volume prunevolumes not referenced by any container
docker network prunecustom networks not used by any container
docker builder prunethe build cache (add --all to clear it completely)
docker system prunestopped containers + dangling images + unused networks + build cache
docker system prune -a --volumeseverything above PLUS all unused images and unused volumes — the nuclear option

Remove everything (careful)

The clean-slate commands — understand each before running
# Stop every running container
docker stop $(docker ps -q)

# Remove every container (add -f to skip the stop step)
docker rm $(docker ps -aq)

# Remove every image
docker rmi $(docker images -q)

# Modern, safer spellings of the same idea:
docker container prune -f
docker image prune -a -f
docker system prune -a deletes every image not currently backing a running or stopped container, so a later docker run of a previously-built image has to re-pull or re-build it. Adding --volumes also deletes data volumes — the only loss in this sheet that cannot be recreated. The safe sequence for a nearly-full host: docker system df, then docker container prune, then docker image prune, and only reach for -a --volumes when you have confirmed nothing valuable is left.

Why is Docker using so much disk?

References

FAQ

How do I remove all stopped containers?

docker container prune removes every stopped container in one step (add -f to skip the confirmation). The classic one-liner equivalent is docker rm $(docker ps -aq), which stops nothing itself — combine with docker stop $(docker ps -q) to clear running containers too.

What is a dangling image?

A dangling image is an image with no tag, shown as : in docker images. It happens when you build a new image with a tag that already existed — the old image loses its tag and is left behind as a dangling layer. docker image prune removes dangling images; they are always safe to delete.

How do I clean up Docker disk space safely?

Start with docker system df to see what is using space. Then docker container prune (stopped containers), docker image prune (dangling images), and docker builder prune (build cache) — none of these delete volumes or images still in use. Use docker system prune -a --volumes only when you also want to drop unused images and data volumes.

Does pruning remove my volumes?

No — except when you add --volumes to docker system prune, or run docker volume prune directly. Plain image/container prune never touches volumes, which is intentional: volumes hold the persistent data. That is also why orphaned volumes from deleted projects are the most common source of hidden disk use.