Increase maximum size of Docker volume on Windows

Increase maximum size of Docker volume on Windows

Since a few years, Docker Desktop on Windows is using the Windows Subsystem for Linux (or WSL in short) in order to properly function. This means that the system works without having to sacrifice performance too much, but it also comes with a few caveats or shortcomings. One of these being the maximum size of the data volume that’s being used by Docker on Windows which is 250GiB (or 1TiB on more modern installations of Windows). Once the containers you created hit this limit, the system stops working and no more data can be written to the Docker volume.

There are a few workarounds to overcome this limitation but since the information on Microsoft’s website is not specifically targeted at Docker (but rather at WSL Linux distributions in general) and most other guides out there are outdated, I decided to write down exactly what I did.

Follow the steps below to increase the size of your Docker data volume. Note that these instructions are for version 2 of the Windows Subsystem for Linux (WSL 2) and that these have last been tested in July, 2023.

  1. Start by finding out where the virtual Docker disk is stored on your hard drive. This is typically in the folder %LOCALAPPDATA%\Docker\wsl\data or a similar place. There should be a file named ext4.vhdx in this folder. You can easily open this folder by simultaneously pressing the Windows and R button (which will open the “Run” dialog). Copy and paste %LOCALAPPDATA%\Docker\wsl\data and press enter to open the folder (if it exists).
  2. Open a new PowerShell window by clicking the start button and typing PowerShell. You need administrator privileges for the commands that are about to follow.
  3. Shutdown WSL by running wsl --shutdown.
  4. Open the Diskpart utility by running diskpart. A new terminal window should pop up which will allow you to run diskpart commands.
  5. Select the virtual Docker volume that you identified during the first step of this guide by running this command Select vdisk file="<pathToVHD>" (and replacing <pathToVHD> by the path to your virtual disk, i.e. %LOCALAPPDATA%\Docker\wsl\data\ext4.vhdx).
  6. Execute expand vdisk maximum=<sizeInMegaBytes> (replace <sizeInMegaBytes> with the maximum amount of space in megabytes that Docker is allowed to use, for example 1024000 for 1TB of space) to increase the volume’s virtual size. After this step, the volume’s virtual size is already expanded, but Docker nor WSL are yet aware that they can actually use more space.
  7. In order to WSL aware that it can expand the file system, open a new PowerShell window and type ubuntu to open a new Ubuntu shell. If Ubuntu is not yet installed on your system, follow this guide.
  8. Run df -h to see a list of all file systems that are currently mounted in the system. Find the entry where the “Mounted on” column says /mnt/wsl/docker-desktop-data/isocache and remember the value in the “FileSystem” column. This is typically something like /dev/sdb, /dev/sdd or something similar.
  9. Finally, also resize the volume in your WSL distribution such that Docker is aware of the larger volume by running this command in Ubuntu: sudo resize2fs /dev/sdb <sizeInMegabytes>M and replace <sizeInMegabytes> by the size you choose in step 6 and /dev/sdb by the name you found during step 8.
  10. Now, start Docker Desktop again and you should be able to use more than 250GiB with your Docker installation.

Leave a Reply

Your email address will not be published. Required fields are marked *