Skip to content

Instantly share code, notes, and snippets.

@JanoPL
Last active October 25, 2025 00:40
Show Gist options
  • Select an option

  • Save JanoPL/917c378a1eb662a3b41d5b2d0b1e8aef to your computer and use it in GitHub Desktop.

Select an option

Save JanoPL/917c378a1eb662a3b41d5b2d0b1e8aef to your computer and use it in GitHub Desktop.
Move docker VHDX ext4.vhdx to new location for docker desktop in WSL 2. Move Ubuntu ext4.vhdx to new location

Docker Dekstop Data

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         2

Export 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

Ubuntu

To move to new location Ubuntu distro, the steps are the same as docker-dekstop-data.

  1. Shutdown or terminate distro for example "Ubuntu-22.04" wsl --shutdown
  2. Create directory mkdir -p D:\Docker\wsl\Ubuntu-22.04
  3. Export distro wsl --export Ubuntu-22.04 "D:\Docker\wsl\Ubuntu-22.04\Ubuntu-22.04.tar"
  4. Unregister existing one shell wsl --unregister Ubuntu-22.04
  5. 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
  6. Check if default user is set correct as previous distro, if not you can change in windows registry regedit.exe under Key HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss only 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment