Prune

How-to

Docker taking up disk space on Mac and Windows

Docker Desktop keeps images, containers, volumes and build cache in one virtual disk. Deleting things inside Docker does not always shrink that file. Often 10 to 50 GB or more is reclaimable.

1. See what Docker holds

docker system df
docker system df -v

The RECLAIMABLE column shows what a prune can free.

2. Run docker system prune

docker system prune          # stopped containers, unused networks, dangling images, dangling build cache
docker builder prune         # build cache only (add -a for all of it)
docker system prune -a       # also every image no container uses
docker system prune -a --volumes   # also unused volumes: check first

--volumes is the dangerous one. Databases often live in volumes, so run docker volume ls before you add it.

3. Shrink the disk image on Mac

Docker Desktop stores everything in ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw. It is a sparse file, so Finder may show a size far above what it really uses. Check the real figure:

du -sh ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw

After a prune, quit and restart Docker Desktop and the space normally comes back. You can also lower the cap under Settings, Resources, Disk image size. Troubleshoot, Clean / Purge data wipes everything, so treat it as a last resort.

4. Shrink the disk image on Windows

With the WSL 2 backend the disk is %LOCALAPPDATA%\Docker\wsl\data\ext4.vhdx. Newer Docker Desktop builds may name the file differently inside the same Docker\wsl folder. It grows but never shrinks on its own. Prune first, then quit Docker Desktop and compact it:

wsl --shutdown
diskpart
select vdisk file="C:\Users\<you>\AppData\Local\Docker\wsl\data\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exit

What is safe and what is not

Safe: stopped containers, dangling images, build cache, and images you can pull again. Not safe: deleting Docker.raw or ext4.vhdx by hand. That removes every image, container and volume in one go, including database data that exists nowhere else.

Or let Prune do it

Prune clears Docker build cache and unused images through the Docker CLI when Docker is running, and lists the Docker disk image by name so you decide about it. It is never pre-selected. The free scan shows every file before you pay. Pro is $15 a year or $29 once ($19 until 20 December 2026).

FAQ

Why is Docker.raw still huge after I deleted images?

Deleting images frees space inside the virtual disk, but the disk file does not always shrink right away. Restart Docker Desktop and check real usage with du -sh on the file. On Windows the ext4.vhdx file only shrinks when you compact it.

Is docker system prune safe?

It removes stopped containers, unused networks, dangling images and dangling build cache. It does not touch running containers or volumes unless you add --volumes. Add -a only if you are happy to re-pull every unused image.

Will docker system prune delete my database data?

Not by default. Volumes are kept unless you pass --volumes. Check docker volume ls first, because databases often live in volumes that no image contains.

Does Prune clear Docker?

Prune clears Docker build cache and unused images through the Docker CLI when Docker is running. It lists the Docker disk image by name for manual review and never selects it for you.

Related