Leveraging WSL2 as of means to containerize environments

Andrew Nyzhnyk
2 min readAug 24, 2023

--

We have come a long way since the initial introduction of the WSL platform. Although its current state is quite magnificent to say the least, the ability to customize, or to be precise — its ease of use — leaves much to be desired.

Some acknowledgments to be disclosed. This publication covers the ‘least effort / most yield’ steps One could bestow upon his WSL instances using tools provided out of the box. In order to supercharge your workflow, a utility called LxRunOffline might be the answer.

Now that we got that out of the way, let us discuss some of the most prolific options that are hidden beneath the reach of Google’s first pages.

Photo by Derek Oyen on Unsplash

Creating multiple instances of the same Linux distribution

Microsoft Store provides a user friendly interface for getting started with WSL — just pick a desired flavor of Linux and click install. Alas, this feature does not come without disadvantaged — users are restricted to a single instance per distribution.

Solution for this problem is achieved with the help of the

List of all currently available WSL2 distributions can be found here. As an example, we will be installing Debian.

curl -L https://aka.ms/wsl-debian-gnulinux -o debian.zip

Extract local .appx file, in this case it’s — DistroLauncher-Appx_1.12.2.0_x64.appx. Rename it into a zip archive. Extract install.tar.gz and run the following command:

wsl --import debian-test D:\vms\debian-test install.tar.gz

Finally, You can access the shell of the newly created WSL instance:

wsl -d debian-test

To set it as a default WSL distribution:

wsl --set-default debian-test

Create a new user (non-interactively — Debian specific skip of gecos):

adduser --disabled-password --gecos '' -s /bin/zsh username

Setting a default user for a distribution

vim /etc/wsl.conf

[user]
default=username

TODO

installations: git, zsh, htop;
configurations: sudo

Distribution cloning

A WSL distribution can by cloned by simply exporting and reimporting it again.

wsl --export *name* - | wsl --import *clone-name* *installpath* -
wsl --export debian - | wsl --import debian-clone D:\vms\debian-clone -

--

--

Andrew Nyzhnyk
Andrew Nyzhnyk

Written by Andrew Nyzhnyk

Passionate software developer, audiophile, and a keyboard enthusiast. You won’t believe how fun I am at the parties

No responses yet