While docker commands like docker system prune
reduce the space, that’s typically not where the disk usage comes from. The real culprits are the data volumes.
Docker on Windows doesn’t automatically reduce the disk size of the underlying VHDX volume – it only ever grows. So, for example, if you delete a large database in your Docker volume, Windows doesn’t actually recover the newly-freed space immediately. Over time you may find you eventually need to fix this manually.
This post describes how to optimize the VHDX file to reduce the disk usage to only what is actually required. Note that the Optimize-VHD
command only is available when Hyper-V is enabled, and Hyper-V is only available on Windows 10 Pro, not Home.
If you still are low on space, it looks like there are unofficial ways of moving the VHDX volume to another drive, but I haven’t tested this.
Update 1/27/23:
Following a routine minor Windows upgrade, Docker wouldn’t start anymore. I made the mistake of uninstalling Docker Desktop – which quietly deleted my docker-desktop-data volume and thus all my container volumes (including my databases). Next time I won’t forget to do that that prior to uninstalling.
So upon reinstalling Docker Desktop it reverted to creating the VHDX volume under AppData again. Fortunately, moving the volume as described in the link above is actually a supported method now, but be sure to set the version number properly when importing the new tarball. So immediately after installing Docker Desktop, launch and then quit it. Your commands are (in an admin terminal):
wsl --shutdown wsl --export docker-desktop-data docker-desktop-data.tar wsl --unregister docker-desktop-data wsl --import docker-desktop-data D:\Docker\wsl\data\ docker-desktop-data.tar --version 2
Then you can restart Docker Desktop and it will use the new volume location.
It’s also a good idea to limit the vmmem usage per this link. I created %AppData%\.wslconfig
with this:
[wsl2] memory=10GB