How to Clear Docker Cache and Reclaim Disk Space on Mac
Docker Desktop stores Linux containers and images in one disk-image file on macOS. Inspect actual use first, prune only unneeded objects, and protect volumes that contain persistent data.
Why Docker Takes Up So Much Space on Mac
Docker is one of the most common reasons a developer's Mac runs out of disk space, and the reason is architectural. macOS cannot run Linux containers natively, so Docker Desktop spins up a lightweight Linux virtual machine behind the scenes. Everything Docker stores — images, containers, volumes, and the build cache — lives inside that VM, packed into a single large disk-image file on your Mac.
On Apple's default file system that file is typically Docker.raw, found at:
~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw
Docker.raw is a sparse disk image: its configured maximum size can be much larger than the host space it currently consumes. Docker says current Docker.raw files normally return host space within seconds after images are deleted; older Docker.qcow2 files reclaim it in the background. Some file tools show the maximum rather than actual allocation, so do not assume the largest number is reclaimable data.
How to Check How Much Space Docker Is Using
Before you delete anything, find out where the space is going. Docker ships a built-in command that reports disk usage by category. With Docker Desktop running, open Terminal and run:
docker system df
This breaks usage down into Images, Containers, Local Volumes, and Build Cache, showing the total size and — crucially — how much is reclaimable. Add the -v flag for a verbose, per-item breakdown:
docker system df -v
To see the actual on-disk size of the virtual-disk file from macOS's perspective, use du:
du -sh ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw
Compare Docker's object report with actual host allocation. Confirm the current disk-image location and usage in Docker Desktop > Settings > Resources > Advanced; Docker warns that other tools may display the configured maximum instead.
Reference: Docker Desktop for Mac disk-image guidance.
How to Prune Docker Images, Containers, and Cache
Docker's prune commands remove unused objects. The right one depends on how aggressive you want to be. Make sure any containers you care about are running or intentionally stopped before you prune, because these commands will delete stopped and unused resources.
Targeted pruning
Clean up one category at a time when you want control:
docker container prune— removes all stopped containers.docker image prune— removes dangling images (untagged layers left over from rebuilds). Add-ato also remove any image not used by a container.docker builder prune— clears the BuildKit build cache, often one of the largest hidden consumers.docker volume prune— removes volumes not attached to any container. Use with care: volumes hold persistent data like databases.
The nuclear option
To reclaim everything unused in one command, run:
docker system prune -a --volumes
This removes all stopped containers, all networks not in use, all dangling and unreferenced images, all build cache, and all unused volumes. It is the fastest way to recover space but the most destructive — read the confirmation prompt carefully before typing y.
--volumes flag will delete unused named volumes, which can include the data behind local databases and other stateful services. If you have a Postgres or MySQL container's data you want to keep, omit --volumes or make sure that volume is attached to a container first.
How to Reclaim Host Space from Docker.raw
Current Docker Desktop versions normally reclaim host space from Docker.raw shortly after images are deleted. Use the least destructive path first.
-
1
Prune first. Run
docker system prune -a(add--volumesonly if you are sure) so the space is actually free inside the Docker VM before you try to reclaim it. -
2
Open Docker Desktop settings. Click the Docker menu-bar icon, choose Settings, then go to Resources > Advanced.
-
3
Wait and verify actual allocation. Docker says
Docker.rawnormally returns host space within seconds. Recheck the actual size rather than the configured maximum. -
4
Trigger reclamation if needed. Docker documents
docker run --privileged --pid=host docker/desktop-reclaim-spacefor manually triggering host-space reclamation after unneeded images are deleted. -
5
Verify the reclaim. Run
du -sh ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.rawagain — the file should now be dramatically smaller.
Clean / Purge data and reducing the disk-image maximum can delete Docker data. Treat either as a reset, back up anything required, and use it only when pruning and documented reclamation are insufficient.
How to Keep Docker From Bloating Again
Reclaiming space once is easy; keeping it reclaimed takes a little discipline. A few habits go a long way:
- Prune on a schedule. Run
docker system prune(without-a) weekly to clear stopped containers and dangling images before they pile up. - Use multi-stage builds. Multi-stage Dockerfiles keep final images small by discarding build-time layers, which reduces both image size and cache churn.
- Tag and remove old images. Explicitly
docker rmiimages you no longer need instead of letting untagged layers accumulate. - Cap the build cache. Use
docker builder prune --keep-storage 10GBto bound how much build cache Docker retains. - Set the disk limit. A sensible virtual-disk limit in Docker Desktop's settings prevents Docker.raw from ever consuming your whole drive.
Finding Docker Bloat with TrimyMac
Docker's disk usage hides inside a single opaque file buried deep in ~/Library/Containers, which is exactly the kind of thing macOS storage tools lump into "System Data" and never explain. TrimyMac scans your disk and surfaces the largest space consumers — including oversized virtual-disk files like Docker.raw — so you know at a glance when Docker is the culprit rather than guessing.
While the actual pruning is best done with Docker's own commands (to avoid corrupting the VM), TrimyMac tells you when it is time to prune and how much you stand to reclaim, then helps you clear the surrounding developer clutter — stale caches, logs, and derived data — in the same pass.
Find the Space Docker Is Hiding
TrimyMac pinpoints oversized files like Docker.raw and clears developer clutter across your Mac in one click. Free download for macOS.
Download TrimyMac FreeFrequently Asked Questions
Why is Docker.raw so large on my Mac?
Docker.raw is the disk image that holds Docker Desktop's Linux containers and images. Its configured maximum can be larger than actual host allocation. Docker says current Docker.raw files normally reclaim host space within seconds after images are deleted; use Docker's disk report and Settings panel before deciding a reset is needed.
What does docker system prune actually delete?
docker system prune removes all stopped containers, all networks not used by at least one container, all dangling images, and unused build cache. Adding -a also removes any image not currently used by a container, and adding --volumes removes unused volumes too. It does not touch running containers or images in active use. Always read the confirmation prompt, especially before using --volumes, which can delete database data.
Will pruning Docker delete my data?
It depends on the command. Pruning containers and images is safe for persistent data, because that data typically lives in volumes. However, docker volume prune and the --volumes flag on docker system prune will delete volumes that are not attached to a container — which can include your local database contents. If you have stateful data you want to keep, avoid those flags, or ensure the relevant volume is attached to a running container before pruning.
How do I shrink the Docker disk image after pruning?
Prune only unneeded images first, wait briefly, and check actual host allocation. If space is not returned, Docker documents docker run --privileged --pid=host docker/desktop-reclaim-space. Clean / Purge data is a destructive reset and should not be the default response.
How can I stop Docker from filling up my disk again?
Prune regularly (a weekly docker system prune is a good baseline), use multi-stage builds to keep images small, bound the build cache with docker builder prune --keep-storage, and set a virtual-disk size limit in Docker Desktop's Resources settings so Docker.raw can never consume your entire drive. Removing images you no longer need with docker rmi instead of letting untagged layers accumulate also keeps usage low over time.