Docker never deletes anything on its own. Every image you pulled, every layer a build produced, every stopped container and every volume stays until you remove it. After a few months of builds it is common to find 30 to 100 GB in Docker, most of it build cache and old images nobody uses.
Most of it is safe to clean, but not all of it: a volume can hold the only copy of a database. This guide shows how to see where the space is, how to clean each part from the safest to the riskiest, and the parts that work differently on a Mac and on Ubuntu.
See where the space goes
Start with Docker’s own summary:
docker system df
It has four lines: images, containers, local volumes and build cache, each with a total and a “reclaimable” column. Reclaimable is what nothing uses right now. Add -v for one line per image, container, volume and cache record:
docker system df -v
On Ubuntu everything lives in /var/lib/docker, so sudo du -sh /var/lib/docker gives the real total. On a Mac, Docker Desktop keeps it all inside a virtual disk; see the Docker Desktop section below.
Build cache: the biggest and safest part
Each docker build with BuildKit keeps its intermediate layers so the next build is fast. On a machine that builds often, this is usually the largest line in docker system df.
docker builder prune # cache records no build uses now
docker builder prune --filter until=168h # only records unused for a week
docker builder prune -a # all of it
The only cost is time: the next build of each project runs every step again. Keeping the recent week with until is a good middle ground. If you use more than one builder (docker buildx ls), each has its own cache; pass --builder <name> to clean another one.
Dangling and unused images
A dangling image is one without a tag, shown as <none> in docker images. It is what is left when you build or pull a new version under the same tag. Nothing refers to it, so removing it costs nothing:
docker images --filter dangling=true
docker image prune
Unused images are tagged images that no container uses, such as an old postgres:16 after you moved to 18. Removing them means pulling or building them again when you need them:
docker image prune -a # every image no container uses
docker image prune -a --filter until=720h # only those created more than 30 days ago
docker rmi <image> # one image by name or ID
Sizes in docker images count layers shared between images more than once, so removing one image may free less than its size. docker system df is the true total.
Stopped containers and their logs
A stopped container keeps its writable layer, which is small unless the program wrote files inside the container instead of a volume.
docker ps -a --filter status=exited
docker container prune
Container logs are a different story. With the default json-file log driver, a container that logs a lot can write gigabytes, and the log stays as long as the container exists. On Ubuntu you can see them directly:
sudo sh -c 'du -sh /var/lib/docker/containers/*/*-json.log' | sort -h | tail
Removing and recreating the container clears its log. To stop it from growing again, set a limit for new containers in /etc/docker/daemon.json (on a Mac: Docker Desktop › Settings › Docker Engine) and restart Docker:
{ "log-driver": "json-file", "log-opts": { "max-size": "10m", "max-file": "3" } }
Volumes: check before you prune
Volumes are where containers keep their data: databases, uploaded files, caches. A volume that no container uses right now may still be the data of a project you only stopped.
docker volume ls
docker volume ls --filter dangling=true # volumes no container uses
docker volume rm <name> # remove one you checked
docker volume prune # anonymous unused volumes (Docker 23+)
docker volume prune -a # also named unused volumes
Since Docker 23, docker volume prune removes only anonymous volumes (the ones with a long hex name) unless you add -a; older versions remove named ones too. Before you remove a named volume, look at what is in it, or back it up:
docker run --rm -v <name>:/data -v "$PWD":/backup alpine tar czf /backup/<name>.tgz -C /data .
Avoid docker system prune -a --volumes unless you really want to start from zero.
Docker Desktop on a Mac: Docker.raw
On a Mac, Docker runs inside a small Linux virtual machine, and all of its images, containers and volumes live in one file: ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw. Finder shows its maximum size (often 64 GB or more), not what it really uses. Ask the disk:
du -sh ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw
The file is sparse: after a prune, Docker Desktop gives the freed space back to macOS, sometimes after a minute or after a restart of Docker Desktop. If it stays large, lower the limit in Settings › Resources › Advanced (Disk usage limit). The last resort is Troubleshoot › Clean / Purge data, which deletes every image, container and volume.
OrbStack and Colima work the same way with their own disk image; the docker commands above clean inside them.
How CleanMate does it
CleanMate puts Docker in the developer junk of Smart Scan, on both systems. It only talks to a Docker daemon on your own machine, and only one that is already running: it never starts Docker and never touches a remote context.
On a Mac (all features), Docker is split into separate items. Untagged build images are ticked and listed one by one with their ID, size and date; each is removed by ID, so an image you untick stays. Build cache records that no build uses are listed one by one, not ticked, and removed by ID with docker builder prune --filter id=…; records shared with an image are marked as freeing no space. Unused images, stopped containers and unused volumes are not ticked: you can expand them to see exactly what their prune command would remove, each volume with its name and driver and anonymous ones marked, and each is cleaned as a whole. OrbStack’s caches and logs are a separate item; its machines and containers are never touched.
On Ubuntu (all features), the desktop app goes one step further: dangling images, build cache records, unused images and unused volumes can each be ticked one by one, and a named volume is marked may hold data. With Docker 23 or newer, cleaning the whole volumes item removes only anonymous volumes, and its size counts only those.
CleanMate does not clean container logs or shrink Docker.raw itself; the sections above show how. If Docker on Ubuntu says permission denied or cannot connect to the daemon, see the Docker permission fix; for Podman, Podman using too much disk space on Ubuntu; for the Linux VM behind Colima, Lima or minikube on a Mac, leftover Linux VMs.
For the rest of a developer machine, see Free up disk space on a Mac as a developer, the same guide for Ubuntu and Xcode using too much space. Minikube, Colima, Lima and Vagrant are in virtual machines and dev infrastructure tools.

