Change WSL Docker image (ext4.vhdx) directory

Change WSL Docker image (ext4.vhdx) directory

Tags
WSL
Windows
Docker
Published
January 11, 2024
Author

Motivation

By default, the ext4.vhdx image file of docker is stored under
C:\Users\[username]\AppData\Local\Docker\wsl\data\ext4.vhdx
It takes plenty of spaces so weโ€™d like to migrate it to somewhere else, like G:\.

Steps

1. Shut down docker process

check WSL running status:
wsl --list -v
notion image
Shut down docker (along with all other WSL distributions)
wsl --shutdown
notion image
ย 

2. Backup data

Backup the original ext4.vhdx to somewhere you like, e.g., "G:\WSL\data\docker-desktop-data.tar"
wsl --export docker-desktop-data "G:\WSL\data\docker-desktop-data.tar"
notion image

3. Delete original image

wsl --unregister docker-desktop-data
notion image
ย 

4. Import data and specify new directory to store image

wsl --import docker-desktop-data "G:\WSL\data" "G:\WSL\data\docker-desktop-data.tar" --version 2
notion image
ย 
Done ๐Ÿ‘