Using WSL 2 on Windows Server 2022 to run Linux containers

Windows Subsystem for 2 (WSL 2) is one of the most popular features for developers on Windows 10 and 11. It has recently been made available on 2022. With this addition, you can now run containers on WSL 2 on 2022 for development and testing purposes.

Preparing your 2022

WSL 2 on Windows Server 2022 has a different requirement than Windows 10 and 11. Before you get started with WSL 2, make sure your OS is up-to-date with the latest patches. WSL 2 requires at least the June 2022 patch Tuesday release, but it's always a good practice to ensure the latest updates are installed. After that, all pre-requisites for WSL 2 to work on Windows Server 2022 can be implemented with:

wsl --install

Now you should have a fully functional environment on your Windows Server 2022 host.

Install on WSL 2 on Windows Server 2022

To install on Windows Server 2022, you need to follow the instructions for the specific distribution you chose on the previous step. Here are the instructions for Ubuntu, according to Docker's documentation page. On your Windows Server 2022, click the Start button, then click on the Ubuntu icon:

LinuxWSL2WS202201.png

This will launch the WSL 2 console. You can now run commands on the Ubuntu Linux image as you would on a regular Linux environment. To get started, let's update the apt package index and install packages to allow apt to use a repository over HTTPS:

sudo apt-get update
 sudo apt-get install
    ca-certificates
    curl
    gnupg
    lsb-release

Now, let's add 's official GPG key:

sudo mkdir -p /etc/apt/keyrings
 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Use the following command to set up the repository:

echo
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install the Docker engine:

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

Now let's verify the installation has been successfully completed:

sudo service docker start
sudo docker version

You should see the details of the Docker engine installed. That's it. You can now run the regular Docker commands you are familiar with. In addition, you can run regular Windows containers on the same host:

LinuxWSL2WS202202.png

Conclusion

WSL 2 can be used on Windows Server 2022 to run Linux containers on Windows Server 2022 for development and testing purposes. Please let us know your thoughts on this scenario on the comments below.

 

This article was originally published by Microsoft’s System Center Blog. You can find the original article here.