Because macOS is Darwin-based (not Linux), Docker Desktop cannot run Linux containers natively. Instead, it spins up a lightweight Linux hypervisor virtual machine.
The entire Linux root filesystem, containerd images, build caches, and volumes are stored inside a single virtual sparse disk file located at:
~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw
1. The Sparse Disk Shrink Problem
When you download a 10 GB Docker image, Docker.raw expands to hold it. When you later run docker rmi to delete the image, the free space is reclaimed inside the virtual Linux ext4 filesystem, but macOS APFS does not know that those host SSD blocks can be trimmed.
As a result, your host Mac storage remains hostage to an oversized virtual disk.
2. Purging Build Caches & Dangling Layers
Step 1: Inspect Current Docker Usage
Run Docker's built-in disk visualizer to see how space is allocated:
docker system df
Step 2: Wipe BuildKit Cache (Huge Space Saver)
BuildKit retains intermediate build layers for multi-stage Dockerfiles that can easily total 30โ50 GB:
docker builder prune -a -f
Step 3: Deep System Prune
Remove stopped containers, unused networks, and dangling images:
docker system prune -a --volumes -f
--volumes: The --volumes flag will remove local persistent volumes not attached to running containers. If you have database containers with persistent data, verify them first.
3. Compacting Docker.raw on APFS
In modern Docker Desktop versions (v4.25+), you can trigger an explicit disk trim through the GUI:
- Open Docker Desktop.
- Click the Troubleshoot icon (the bug icon at the top right).
- Click Clean / Purge data.
- Select Trim disk image.
Alternatively, if you want a complete reset:
rm -rf ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw
Spot Virtual Disks Instantly with DiskAtlas
DiskAtlas highlights virtual disks from Docker, UTM, and Parallels directly in the interactive treemap and Big Wins Reclaim catalog.
Try DiskAtlas Free4. Best Practices for Lean Docker Storage
- Use Multi-Stage Builds: Keep production image sizes under 150 MB.
- Enable VirtioFS: Enables ultra-fast file system sharing with minimal overhead on Apple Silicon.
- Cap Virtual Disk Limit: Set Docker Desktop Virtual disk limit to 32 GB or 64 GB under Settings โ Resources โ Virtual disk limit.