I like WSL2. It’s lightweight, and integrates well with Windows as files are easily transferrable into and out of containers.

I’ve recently glanced at Microsoft’s docs regarding importing Linux distros in WSL which includes an example of exporting CentOS from Docker and importing it into WSL. It’s quite simple to do. However, you do need to have Docker installed.

For this example, I will be importing a Docker image of Hugo, a static site generator, into WSL.

Steps

First, pull the image and create the container.

$ docker pull klakegg/hugo:debian
$ docker create klakegg/hugo:debian
4f927a34762880a037625e5584b475c15a1c776de6ef5561ef5632bbdf081fef

Then, export the container into a tar file. Don’t forget to cleanup by removing the container after exporting.

$ docker export 4f927 --output="hugodeb.tar"
$ docker rm 4f927

Setup where you want to keep your WSL virtual disks if you want to keep it tidy. For example, I store it at C:\\Users\\User\\WSL. Import the rootfs tar file into WSL. The syntax follows: wsl --import <dist_name> <vhdx_directory> <tar_file>.

$ wsl --import Hugodeb Hugodeb hugodeb.tar
Import in progress, this may take a few minutes.
The operation completed successfully.

You can then list WSL Linux distributions using wsl --list command. Then, to use the image:

$ wsl -d Hugodeb

Or, if you use Windows Terminal, a profile is automatically added, so you can run it easily from there. Replace ‘Hugodeb’ with your distribution name.

Windows Terminal profile

It is now imported. You can use this method if you want to use a Docker image as a base, say, for a development or a build environment.

Removing the distribution from WSL is as simple as:

$ wsl --unregister <dist_name>

Other distribution

You can also import other Linux distributions not available in the Microsoft store provided it has a Docker image or a compatible rootfs tar file. Debian, for example, has rootfs tar file meant for Docker in their Github repository. This way you can run multiple Debian distributions on the same machine.