Disk space usage

I made a docker compose build command and it downloaded half of the internet, filling up my disk. As an emergency measure I pushed Ctrl-C. Then I executed docker system prune to no avail, then Docker Desktop Disk space extension to no avail.

So what I think has happened that since I pushed Ctrl-C in panic, docker compose did not perform any sort of cleanup.

So how to clean up manually and free the disk space? For example, where does Docker cache downloaded files/temporary files?

My use case is Windows 10 + WSL2 + Docker desktop with WSL integration enabled.

If the files were downloaded to the containerā€™s filesystem, the image size of Docker Desktopā€™s WSL2 distribution has already changed. Pruning data in the VM wil not itself decrease the disk size. On some systems like macOS, I heard that decreasing the disk size is possible from the GUI (I never tried), but on Windows, you need to deal with it manually. I think @meyay somewhere already answered it, but I couldnā€™t find yet.

What I found now is this:

You would need to find where the vhdx is. From powershell it should be here:

$env:USERPROFILE\AppData\Local\Docker\wsl\data\ext4.vhdx

If you have Windows home, you will probably need this:

https://answers.microsoft.com/en-us/windows/forum/all/optimize-vhd-not-found-in-windows-10-home/a727b760-0f82-4d0f-8480-d49eeaeb11a2

Assuming you have pro, after you stopped docker desktop, it could work:

Optimize-VHD -Path "$env:USERPROFILE\AppData\Local\Docker\wsl\data\ext4.vhdx" -Mode Full

Note that iI donā€™t know how stable this operation is. If you can and need, make a backup of data in case you are afraid of losing data in Docker Desktop.

1 Like

diskpart can be used on all Windows 10/11 version to compact the vhdx file:

1 Like

Thanks, this worked!