The WSL 2 docker-desktop-data vm disk image would normally reside in: %USERPROFILE%\AppData\Local\Docker\wsl\data\ext4.vhdx
Follow the following to relocate it to other drive/directory, with all existing docker data preserved (tested against Docker Desktop 4.21.1)
First, shut down your docker desktop by right click on the Docker Desktop icon and select Quit Docker Desktop
Then, open your command prompt:
wsl --list -v
You should be able to see, make sure the STATE for both is Stopped.
command: wsl --shutdown
NAME STATE VERSION
* docker-desktop Stopped 2
docker-desktop-data Stopped 2Export docker-desktop-data into a file
wsl --export docker-desktop-data "D:\Docker\wsl\data\docker-desktop-data.tar"
Unregister docker-desktop-data from wsl, note that after this, your ext4.vhdx file would automatically be removed (so back it up first if you have important existing image/container):
wsl --unregister docker-desktop-data
Import the docker-desktop-data back to wsl, but now the ext4.vhdx would reside in different drive/directory:
before doing this, you must create a directory for the new location, for example mkdir D:\Docker\wsl\data
wsl --import docker-desktop-data "D:\Docker\wsl\data" "D:\Docker\wsl\data\docker-desktop-data.tar" --version 2
Start the Docker Desktop again and it should work
You may delete the D:\Docker\wsl\data\docker-desktop-data.tar file (NOT the ext4.vhdx file) if everything looks good for you after verifying
To move to new location Ubuntu distro, the steps are the same as docker-dekstop-data.
- Shutdown or terminate distro for example "Ubuntu-22.04"
wsl --shutdown - Create directory
mkdir -p D:\Docker\wsl\Ubuntu-22.04 - Export distro
wsl --export Ubuntu-22.04 "D:\Docker\wsl\Ubuntu-22.04\Ubuntu-22.04.tar" - Unregister existing one
shell wsl --unregister Ubuntu-22.04 - Import distro to new location
wsl --import Ubuntu-22.04 "D:\Docker\wsl\Ubuntu-22.04" "D:\Docker\wsl\Ubuntu-22.04\Ubuntu-22.04.tar" --version 2 - Check if default user is set correct as previous distro, if not you can change in windows registry
regedit.exeunder KeyHKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxssonly applying for existing user in your distro you can find your distro by the path, change "DefaultUid" to first user id 1000 in dec or hex 0x000003e8, after changing register key you need restart wsl distro, after login again should be your first user