Reclaim Docker & WSL disk space on Windows — without breaking anything
You deleted the images. You ran docker system prune. Free space didn't budge. That's because Docker Desktop and WSL2 keep everything inside a virtual disk file (ext4.vhdx / docker_data.vhdx) that grows but never shrinks on its own. Reclaiming the space is a two-step job — and deleting the vhdx is the one thing you must not do.
Step 1 — free the space inside the disk (prune)
First, actually remove unused data so there's slack to reclaim:
# remove stopped containers, unused networks, dangling images + build cache
docker system prune -af
# also drop unused named volumes (careful: deletes volume data)
docker volume prune -f
This frees space inside the virtual disk, but the .vhdx file on Windows stays the same size. That's expected — on to step 2.
SweepDisk flags your Docker/WSL virtual disks as "reclaim by pruning — never delete," so you clear caches confidently and leave the vhdx alone.
Step 2 — compact the virtual disk (reclaim it on Windows)
Shut WSL down, then compact the vhdx so Windows gets the freed space back.
The easy way — Optimize-VHD (Hyper-V)
wsl --shutdown
Optimize-VHD -Path "$env:LOCALAPPDATA\Docker\wsl\data\ext4.vhdx" -Mode Full
Optimize-VHD ships with the Hyper-V PowerShell module. The exact path varies by Docker version and WSL distro — for a distro it's usually under %LOCALAPPDATA%\Packages\<distro>\LocalState\.
No Hyper-V? Use diskpart
wsl --shutdown
diskpart
# in diskpart:
select vdisk file="C:\Users\you\AppData\Local\Docker\wsl\data\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exit
Both do the same thing: return the empty space inside the vhdx to your C: drive. It's safe — you're compacting, not deleting.
Keep it from ballooning again
- Prune on a schedule. Build cache is the usual culprit —
docker builder pruneafter heavy image work. - Set a WSL memory/disk cap in
.wslconfigif a single distro keeps growing. - Watch the vhdx size. A monthly scan tells you when Docker/WSL has quietly reclaimed a chunk of your SSD again.
Free categorized scan for Windows 10 & 11. Virtual disks are flagged, never auto-deleted.