Prerequisite:
- You must have WSL enabled with a Linux distribution installed running WSL 2.
- You must have Docker Desktop for Windows installed with the WSL 2 engine enabled and integration checked See the Docker Desktop license agreement for updates on the terms of use.
Run below command in your current WSL Linux distro has enabled integration with Docker:
-
Download the official Ubuntu image:
sudo -E docker pull ubuntu
-
Run the Ubuntu container inside Docker:
sudo -E docker run --name ubuntu-test -it ubuntu
-
Grab the Ubuntu container ID using
grep
andawk
:# Open another tab of terminal and run: dockerContainerID=$(sudo -E docker container ls -a | grep -i ubuntu | awk '{print $1}')
-
Export the container ID to a tar file on your mounted d-drive:
sudo -E docker export $dockerContainerID > /mnt/d/tmp/ubuntu.tar
Once you have a tar file ready, you can import it using the command:
wsl --import <Distro> <InstallLocation> <FileName>
.
To import the Ubuntu distribution tar file into WSL:
-
Open PowerShell and ensure that you have a folder created where you'd like the distribution to be stored.
cd D:\tmp mkdir D:\wslDistroStorage\Ubuntu
-
Use the command
wsl --import <DistroName> <InstallLocation> <InstallTarFile>
to import the tar file.wsl --import Ubuntu-Test D:\wslDistroStorage\Ubuntu .\ubuntu.tar
-
Use the command
wsl -l -v
to check which distributions you have installed.
- Finally, use the command
wsl -d Ubuntu-Test
to run your newly imported Ubuntu Linux distribution.