dockerwindows-subsystem-for-linuxdiskspace

How to properly resize disk usage in docker desktop WSL2?


I am having issues with too much space utilized by docker and wsl2 *.vhdx images.

tried running:

docker system prune --all

Restarting the pc.

Still the vhdx images are too big. In my case the image size grown up to 250GB!


Solution

  • Turns out there is a way to shrink the vhdx images properly in windows:

    1. Run in cmd: docker system prune (optional —all), to clean up disk space
    2. Right mouse click on docker desktop in system tray -> quit
    3. Run in cmd: wsl --shutdown
    4. Run Optimize-VHD -Path "$env:LOCALAPPDATA\Docker\wsl\data\ext4.vhdx" -Mode Full, this will resize the vhdx images

    Same way you can try to find vhdx images that utilize too much space and optimize them as well. You can use TreeSize(Bing it: Tree Size Windows) to find which image takes the most of the space and optimize them.

    P.S. dont forget to run docker system prune