Once I started playing with Docker on Windows it quickly turned out that latest version heavily rely on WSL 2, in comparison to an older Hyper-V based approach. One thing that changed significantly during this technology transition was lack of a setting screen to actually define the location (and other params), where the containers and downloaded images should be stored. As the space they occupy grows really fast and default is not always the best place for it!
I don’t understand why, but because of such practices (i.e. most of developer tools blindly assuming only drive C: exists inside the PC and is also infinite storage at the same time), the free space on a system drive runs extremely fast towards 0MB available. I would be very happy, if there would have been any management console tool, configuration file or at least a guide on how to reconfigure it to utilize drive D: instead. There is a Microsoft documentation, which describes a WSL configuration file, but it seems to be a bit old these days. At the same time I couldn’t find anything useful on Docker website itself.
What I finally spot was this tricky solution from Franks Chow on StackOverflow.
Let me quote all required steps here too:
Quit Docker Desktop
Open Command Prompt (or PowerShell)
List existing WSL storages
$ wsl --list -v
Expected output:
NAME STATE VERSION * docker-desktop Running 2 docker-desktop-data Running 2
Turn off WSL
$ wsl --shutdown
Output:
NAME STATE VERSION * docker-desktop Stopped 2 docker-desktop-data Stopped 2
Create following path (with all subfolders):
$ mkdir D:\Docker\wsl\data\
Export containers and their data. This step can actually take some time depending on the size of the original ext4.vhdx file.
$ wsl --export docker-desktop-data "D:\Docker\wsl\data\docker-desktop-data.tar"
Unregister the container data from WSL. It will also automatically delete the ext4.vhdx from original location.
$ wsl --unregister docker-desktop-data
Import the container data, but keep it into another location (i.e. on drive D: as defined above). This will automatically create ext4.vhdx file from the backup.
$ wsl --import docker-desktop-data "D:\Docker\wsl\data" "D:\Docker\wsl\data\docker-desktop-data.tar" --version 2
Delete the exported .tar file: D:\Docker\wsl\data\docker-desktop-data.tar and nothing more!
Start Docker Desktop and run your containers.
This whole approach seems to be a little hackish. I am surprised it was the only working solution. Is there anything actually blocking or preventing Docker Team or Microsoft to simplify this setting and providing it as nice UI anywhere or as single command at least?
Great it’s achievable and done!
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!