# Docker cleanup cheat sheet: reclaim disk

> Docker cleanup cheat sheet: docker system df and prune, removing stopped containers, dangling and unused images, volumes and build cache — verified against the official docs.

- Page URL: https://itinsighthub.com/docker/cleanup/
- Markdown variant of this page: append `?format=md` to any URL on this site or send `Accept: text/markdown`.
- Full site index for AI assistants: https://itinsighthub.com/llms.txt
- Full site export: https://itinsighthub.com/llms-full.txt

# 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 `:` layer left behind when a tag is reused — those are always safe to remove.

Published August 22, 2026

## 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*

| Command | Removes |
| --- | --- |
| docker container prune | all stopped containers |
| docker image prune | dangling images only (untagged :) |
| docker image prune -a | all images not used by at least one container (keeps nothing spare) |
| docker volume prune | volumes not referenced by any container |
| docker network prune | custom networks not used by any container |
| docker builder prune | the build cache (add --all to clear it completely) |
| docker system prune | stopped containers + dangling images + unused networks + build cache |
| docker system prune -a --volumes | everything 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?

- **Dangling images.** Every `docker build` that reuses a tag orphans the previous image as an untagged `:` layer. `docker image prune` removes exactly these.
- **Stopped containers.** Every `docker run` without `--rm` leaves a stopped container behind, and each one keeps its writable layer. Use `--rm` for one-off jobs or prune stopped containers regularly.
- **Build cache.** Docker caches each Dockerfile layer to make rebuilds fast, and that cache grows. `docker builder prune` clears it; rebuilds get slower until the cache rebuilds.
- **Volumes.** Named volumes are never touched by image/container prune, so orphaned database volumes from deleted projects pile up. `docker volume prune` is the only thing that removes them.
- **Logs.** A container that logs heavily grows its JSON log file, governed by the logging driver's `max-size`/`max-file` options — configure them on the daemon or per-container if a single container balloons.

## References

- [docker system df](https://docs.docker.com/reference/cli/docker/system/df/) — the official disk-usage command.
- [docker system prune](https://docs.docker.com/reference/cli/docker/system/prune/) — what each prune variant removes.

## 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.

## Related tools

- [IPv4 subnet calculator](https://itinsighthub.com/subnet-calculator/) — break any CIDR block into network, range, broadcast and usable hosts.
- [IP range to CIDR](https://itinsighthub.com/ip-range-to-cidr/) — turn an arbitrary address range into its minimal covering CIDR blocks.
- [VLSM calculator](https://itinsighthub.com/vlsm-calculator/) — split a block into right-sized subnets by host requirements.

---

© 2026 ITInsightHub · [About](https://itinsighthub.com/about/) · [Contact](https://itinsighthub.com/contact/) · [Privacy](https://itinsighthub.com/privacy/)
