Hey folks! I'm using Docker Desktop on Windows with WSL2 (specifically Ubuntu 22.04), and I'm really frustrated with how my disk space is being used. The VHDX files I'm dealing with are:
- C:UserslenovoAppDataLocalDockerwsldiskdocker_data.vhdx: 11.7GB
- C:UserslenovoAppDataLocalPackagesCanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgscLocalStateext4.vhdx: 8.5GB
The strange thing is that in Docker Desktop, I have absolutely no containers, images, or volumes. Plus, I ran commands like `sudo apt autoremove -y && sudo apt clean` in Ubuntu to try and free up space.
I attempted to compact the files using PowerShell and Diskpart, and ran several Docker pruning commands, but the total for both VHDX files only reduced from ~18GB to around 18.2GB. It seems like no matter what I do, these files just keep getting bigger over time. Is anyone else experiencing this, or am I missing some secret command to reclaim space?
2 Answers
There’s not really a ‘magic’ solution to this, unfortunately. The way virtual disks function is just how they are designed, and Docker can’t automatically shrink these files. Since you’ve already cleaned everything Docker-related, you might want to check out some guides on how to shrink VHDX files specifically for WSL or Hyper-V. If it continues to be a headache, you could also consider using a custom VM setup, like VMware, where managing disk space is a bit easier.
I usually have good luck with these steps:
1. Run `sudo docker system prune -a`
2. Shut down WSL with `wsl --shutdown`
3. Open Diskpart and run:
- `select vdisk file="C:WSL-Distros...ext4.vhdx"`
- `attach vdisk readonly`
- `compact vdisk`
- `detach vdisk`
- `exit`
This process seems to compact the VHDX for me without too much fuss!
I've spent days trying different methods too. I totally get how you feel—it's odd that these files can take up space and still show as empty!