Migrating WSL and Docker to Another Disk
Last updated on May 14, 2026 pm
This article is currently an experimental machine translation and may contain errors. If anything is unclear, please refer to original Chinese version. I am continuously working to improve the translation.
When using Docker Desktop + WSL 2 on Windows, the C drive can easily fill up. The usual culprits are two kinds of data:
- WSL data, such as Ubuntu's
ext4.vhdx - Docker's images, containers, and volume data, which are typically managed by Docker Desktop's WSL backend
What is ext4.vhdx?
A WSL distribution, such as Ubuntu, is essentially a Linux system registered inside Windows; most of its Linux filesystem content is stored in a virtual disk file, usually ext4.vhdx.
Below is how to migrate these.
Preparation
Prepare the target directories for migration
I plan to migrate to the following locations respectively:
D:\wsl for Ubuntu
D:\docker for Docker images, containers, volumes, and other dataYou can specify your own directories.
Check the WSL status
Run
wsl -l -vMake sure it is WSL2, otherwise the following steps do not apply.
The output on my machine is
NAME STATE VERSION
* Ubuntu Stopped 2
docker-desktop Stopped 2We will migrate Ubuntu later. If the Linux distribution you use is not Ubuntu, simply replace Ubuntu with the name shown in the NAME column.
Shut down WSL and Docker
Run
wsl --shutdownand close Docker Desktop.
Migrating WSL
First, export Ubuntu:
wsl --export Ubuntu D:\wsl\Ubuntu.vhdx --format vhdThis step may take a while.
Verify that the export succeeded:
Get-Item D:\wsl\Ubuntu.vhdxAfter confirming success, unregister the original Ubuntu:
wsl --unregister UbuntuThen organize the directory:
New-Item -ItemType Directory -Force D:\wsl\Ubuntu
Move-Item D:\wsl\Ubuntu.vhdx D:\wsl\Ubuntu\ext4.vhdxRe-import it:
wsl --import-in-place Ubuntu D:\wsl\Ubuntu\ext4.vhdxCheck whether it succeeded:
wsl -l -v
wsl -d UbuntuIf you can enter Ubuntu, the migration was successful.
Here, if you launch WSL separately from Windows Terminal, you may find that the previous configuration no longer works:
不存在具有所提供名称的分发。
错误代码: Wsl/Service/CreateInstance/ReadDistroConfig/WSL_E_DISTRO_NOT_FOUNDSolution: change the content of the "Command line" field shown in the image to
C:\WINDOWS\system32\wsl.exe -d Ubuntu --cd ~Then save and reopen it.

Migrating Docker
You can migrate directly using Docker Desktop's GUI.
Open Docker Desktop, go to Settings -> Resources -> Advanced, modify the Settings -> Resources -> Advanced options as shown in the image, change them to the directory location you set, and then click Apply & Restart.
