I am using Docker on Windows with WSL 2 backend. The hard disc image file on path C:\Users\me\AppData\Local\Docker\wsl\data is taking up 160 GB of disc space. I have tried the command:
Optimize -VHD -Path C:\Users\me\AppData\Local\Docker\wsl\data\disc.ext4 -Mode Full
but it only clears up a couple of MB.
I also tried to clean docker with docker prune but that doesn't help either.
I also tried modifying the .wslconfig file, but it turns out you can't set disc space usage that way, only RAM usage.
I am not sure why is it taking up so much space in the first place, considering I only have 5 containers and images. Any help/advice is highly appreciated.
Additional info:
docker image ls -a
... cumulatively shows only 2 or 3 GB taken.
docker container ls -a
... shows 5 containers.
docker info shows (I didnt copy and paste the whole output because it's too long):
Server:
Containers: 5
Running: 2
Paused: 0
Stopped: 3
Images: 5
Kernel Version: 5.4.72-microsoft-standard-WSL2
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 12.37GiB
You may have already resolved this but I came across this article that solved it for me: https://btburnett.com/docker/2021/09/06/reclaiming-hd-space-from-docker-desktop-on-wsl-2.html
The key thing here was the inclusion of a step to run a container (provided by Docker themselves) to send TRIM commands to the hardware abstraction layer:
docker run --rm --privileged --pid=host docker/desktop-reclaim-space
This process ensures that unused sectors are identified and allows Hyper-V to shrink the VHDX file further.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With