A number of times, I want to create a Window Subsystem for Linux instance out of a Docker container.
The main reason for doing something like this is when a particular Linux version is not available for WSL
.
The steps to follow –
Install from Docker Hub
First run the container image from the Docker Hub image
docker run -it ubuntu:22.04 /bin/bash
This runs the container and gives a prompt. Add the necessary updates / software.
apt-get update -y
Export from Docker
Following command to be run while the docker container is running.
Get the container ID by running docker ps
command, then –
docker export --output=<path to tar file>.tar <docker container id>
This exports the docker container to a export.tar
file.
Once exported, the docker container can be stopped and removed.
Import into WSL
Import the exported tar
file into WSL.
wsl --import <instance name> <wsl save directory> <path to tar file.tar>