I have set 512GB as limit in my WSL settings. while ext4.vhdx file honored that limit during docker desktop installation, its seems docker_data.vhdx size is hardcoded to 1TB.
How can I reduce the same?
Share and learn in the Docker community.
I have set 512GB as limit in my WSL settings. while ext4.vhdx file honored that limit during docker desktop installation, its seems docker_data.vhdx size is hardcoded to 1TB.
How can I reduce the same?
I checked my DD on Windows and my data disk is 36GB on the host. The filesystem inside shows it is 1TB. Do you see the same, or is your data disk file itself 1TB?
I thought Docker Desktop supported changing the disk size even on Windows, since it is now not a separate WSL2 distribution, just a mounted disk, but there is no option for changing the disk size in Docker Desktop 4.47.
I know that there is a Resize-VHD in Powershell, but it didnāt work for me. I could resize the filesystem itself, so even if the virtual disk is shown as 1TB disk in Docker Desktop, the filesystem on is only 40GB
For that, I stopped Docker Desktop.
docker desktop stop
Started a shell in Docker Desktopās WSL2 distribution
wsl -d docker-desktop
I could not see the disk, since Docker Desktop detached it when I stopped the desktop. So I reattached it in a Powershell Admin window
wsl -d docker-desktop --mount --bare --vhd C:\Users\myuser\AppData\Local\Docker\wsl\disk\docker_data.vhdx
The above command attached the disk without actually mounting the disk to anyhere, so āmountā in the command only means mounting to the virtual machine from the host. That is why I used the word āattachedā instead. Then I tried to resize the disk, but first I identified it. Ran
lsblk
and I saw one disk that was not mounted anywhere which was 1TB. The other 1TB disk was the actual root disk. My data disk was /dev/sdd, so I ran something like this:
resize2fs /dev/XX 40G
XX is not the real diskname of course. I just donāt want anyone copy-pasting without checking their own disk name if it can be different in any case. So make sure you use the the right path at your own risk.
It complained that it needed e2fsck first. So I executed the command it recommended. And reran the resize2fs command.
After that, when I started Docker Desktop again, and I ran:
docker run --rm -it -v /var/lib/docker:/data bash df -h /data
I saw my data disk was only about 40GB large. So even if the virtual disk remains 1TB, you will not be able to write more on it than 40B. In your case, it could be 512GB or anything you want.
Doing it on from the GUI of Docker Desktop would be better, but it worked for me. And you could also place the data disk to a dedicated partition on the host (from Settings / Resources), so the disk could not grow bigger at least even without changing the filesystem. Iām not sure if the filesystemc hange survives a Docker desktop update for example..
Thanks for the replying back to me.
My disk also starts small with a limit of 1TB, but my workflow requires a lot of writes to the disk. Even though the total amount of space I need never exceeds 512GB, but due wsl not reclaiming freed space automatically, a lot of time I end up running out of space as the vhd file keeps growing beyond 512GB during multiple runs. After that I manually have to compact the disk again which gets pretty annoying.
I did end up using this. I also tried another variant where I tried to create a new dynamically expanding vhd with my prefered size and then copied the filesystem over to it after resizing it to a smaller size using dd. But docker failed to restart when I tried to use my custom disk. I probably should have just formatted the new disk and should have rsynced the data over. But I had already spent too much time battling with this issue. So I canāt spend more time on the same.
For future, it would be great if docker desktop allows manually setting the data disk size from settings. Meanwhile I will keep using the vhd with resized filesystem.
Thanks again for replying back to me.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.