Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set max disk usage for Docker using WSL2

On Windows 11, my docker desktop increasingly uses more disk every time I run docker-compose up. I tracked it to the size of the following file which is currently at about 100GB.

%USERPROFILE%\AppData\Local\Docker\wsl\data\ext4.vhdx

It seems on Windows you'd need to configure the Docker resource usage through .wslconfig; however, I don't see a key on the docs to adjust max disk usage.

like image 202
Hamed Avatar asked Oct 31 '25 07:10

Hamed


1 Answers

I stumbled upon the same issue today! In my case the ext4.vhdx had grown to 265GB.

When I attempted to continue using docker-compose, I recieve the following error message:

failed to copy files: copy file range failed: no space left on device

According to this page: https://learn.microsoft.com/en-us/windows/wsl/disk-space the maxium amount of disk space should by default be either 256GB, 512GB or 1TB, depending on WSL version. So I was a little bit confused that there was no more space left on the device, especially since I had almost 500GB free space left on the disk.

Instead of using diskpart I choose to Resize-VHD which I though would be easier, instead of messing around with diskpart.

  1. Start Powershell as administrator
  2. Navigate to your user folder cd $env:USERPROFILE\AppData\Local\Docker\wsl\data
  3. Enter the following command resize-vhd -Path .\ext4.vhdx -SizeBytes 300GB, after that I was able to continue building with docker-compose!

With the command above, it is possible to limit the max disk usage for Docker when using WSL2.

like image 159
Dr4co Avatar answered Nov 02 '25 20:11

Dr4co