How to Reduce Docker Disk Usage
Updated · MintDisk team
Docker on a Mac keeps everything, images, containers, volumes and build cache, inside one large disk image file managed by Docker Desktop. It grows with every image you pull and every build you run, and it rarely shrinks by itself. This guide shows how to reduce Docker disk usage with Docker's own commands, from the safest to the most thorough.
Every prune command below deletes data permanently. Read what each one removes before you run it, and never prune volumes you have not backed up.
The commands work the same in Docker Desktop and other Docker setups on macOS. The last section covers what is specific to Docker Desktop: the disk image file and its size limit.
Measure what Docker is using
Start Docker Desktop, then ask Docker how much space it uses. This command only reads.
docker system dfThe output has one row per type of data with the columns TYPE, TOTAL, ACTIVE, SIZE and RECLAIMABLE. The RECLAIMABLE column is the space Docker could free because nothing currently uses it.
docker system df -vThe verbose form lists each image, container and volume. For images it shows SHARED SIZE, the layers an image has in common with others, and UNIQUE SIZE, the space that only that image uses. Deleting an image frees its unique size, not its full size.
What each kind of Docker data is
| Type | What it is | Safe to prune? |
|---|---|---|
| Images | Read-only templates you pulled or built | Dangling ones always; unused tagged ones if you can pull them again |
| Containers | Running or stopped instances of an image, with their writable layer | Stopped ones, once nothing inside is needed |
| Volumes | Persistent data, such as database files | Only after you check and back up the contents |
| Build cache | Layers saved to speed up docker build | Yes; builds get slower until the cache is rebuilt |
| Networks | Virtual networks for containers; they use almost no disk | Unused ones, with docker network prune |
Remove stopped containers
Stopped containers keep their writable layer, and with it any data written inside the container, until they are removed.
docker container pruneThis removes all stopped containers. Docker asks for confirmation; add --filter "until=24h" to keep containers stopped in the last day.
Data written inside a container, rather than in a volume, is lost when the container is removed. Copy out anything you need first with docker cp.
Remove unused images
docker image pruneBy default this removes only dangling images: untagged layers left behind when you rebuild an image with the same tag. They are safe to remove.
docker image prune -aWith -a, Docker removes every image that no container uses, tagged or not.
docker image prune -a also deletes base images you will need again. The next docker run or build downloads them, which takes time and bandwidth. Use it when you really need the space.
Clean up the build cache
If you build images often, the build cache can be the largest item in docker system df.
docker builder pruneWithout options it removes dangling build cache. Add --all to remove all unused build cache, or keep part of it with --keep-storage, for example docker builder prune --keep-storage 10GB. Add --filter "until=72h" to remove only cache older than three days.
Current Docker Desktop versions build with Buildx, whose own prune command uses newer names for the size limits: --reserved-space (space always kept for cache), --max-used-space (the most the cache may use) and --min-free-space (free disk space to aim for). For example:
docker buildx prune --reserved-space 10GBOn docker buildx prune, --all has a different meaning than on docker builder prune: it includes internal and frontend images. Check docker buildx prune --help on your version before you combine flags.
After a full build-cache prune, the next build of every project starts from scratch and takes longer.
Volumes: be careful
Volumes hold the data your containers keep, such as databases. Docker never removes them unless you ask.
docker volume ls
docker volume pruneSince Docker Engine 23, docker volume prune removes only anonymous volumes that no container uses. To remove unused named volumes as well, you need docker volume prune --all.
A pruned volume and the data in it cannot be recovered. Check docker volume ls and back up any database or file you need before you remove a volume.
Everything at once: docker system prune
docker system pruneBy default this removes all stopped containers, all networks not used by a container, all dangling images and unused build cache. Volumes are kept, to prevent important data from being deleted. Add -a to remove all unused images as well, and --volumes to remove anonymous volumes.
Because it combines several prunes, docker system prune is convenient but less precise. Running the individual commands above lets you see and control each step.
A safe routine
Run the commands in this order, from the least to the most disruptive, and check docker system df between steps to see what each one freed:
docker container pruneto remove stopped containers.docker image pruneto remove dangling images.docker builder pruneto remove dangling build cache.- Only if you still need space:
docker image prune -aanddocker builder prune --all. - Volumes last, one at a time, after checking what they contain.
Keep Docker small from now on
- Start throwaway containers with
docker run --rm: Docker removes the container as soon as it exits, so it never piles up. - Set a Disk usage limit in Docker Desktop that leaves enough room for the rest of your work.
- Keep the build cache at a size you are happy to spend:
docker builder prune --keep-storage 10GB, or with Buildxdocker buildx prune --reserved-space 10GB, so builds stay fast without the cache growing forever. - Check
docker system dfonce in a while; the RECLAIMABLE column tells you whether pruning is worth it.
Manage Docker Desktop's disk on Mac
On a Mac, Docker's data lives in a disk image file. Docker's documentation gives the example path ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw; the actual location is shown in Docker Desktop under Settings > Resources > Advanced.
- Disk usage limit (Settings > Resources > Advanced) sets the maximum space Docker can use. Older versions call this setting Disk image size.
- Space is freed when you delete images; files deleted inside running containers are not freed automatically.
- Some tools, including Finder, may report the file's maximum size rather than the space it really uses.
Don't move or delete Docker.raw in Finder. Lowering the disk limit, or using Clean up data in the Troubleshoot menu, deletes the disk image, and with it every container and image on this Mac.
Questions and answers
Why is Docker still large after I pruned everything?
Docker's documentation notes that space is only freed when images are deleted, and that files deleted inside running containers are not freed automatically. For that case the Docker Desktop FAQ gives a command, docker run --privileged --pid=host docker/desktop-reclaim-space, that reclaims the space; it can take a few minutes.
Is docker system prune safe?
It never removes volumes or running containers without extra flags, so your persistent data is safe. It does remove stopped containers and their data, unused networks and build cache, so read the list it prints before you confirm.
How do I see what a volume holds before removing it?
docker volume inspect <name> shows where it is mounted and which labels it has. Containers that use it are listed by docker ps -a --filter volume=<name>.
Where are Docker images stored on a Mac?
Inside Docker Desktop's disk image file, not as separate files you can browse in Finder. Use the Docker CLI or Docker Desktop's Images view to see and remove them.
See Docker's leftovers next to your other developer data
MintDisk's Developer Pack lists dangling images and stopped containers with their size and removes them with Docker's own prune commands; Deep cleanup can also clear Docker's unused build cache. Volumes and tagged images are never touched. Removal is permanent, as with the commands above, and Docker must be running.
Related
Sources
- Docker Docs: docker system df
- Docker Docs: docker image prune
- Docker Docs: docker container prune
- Docker Docs: docker builder prune
- Docker Docs: docker buildx prune
- Docker Docs: docker volume prune
- Docker Docs: docker system prune
- Docker Docs: Docker Desktop for Mac FAQ
- Docker Docs: Docker Desktop settings
First published . Commands and menu paths were checked against the sources above on the update date.