Windows Subsystem for Linux 2 (WSL 2) is one of the most popular features for developers on Windows 10 and 11. It has recently been made available on Windows Server 2022. With this addition, you can now run Linux containers on WSL 2 on Windows Server 2022 for development and testing purposes.
Preparing your Windows Server 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:
Now you should have a fully functional Linux environment on your Windows Server 2022 host.
Install Docker on WSL 2 on Windows Server 2022
To install Docker 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:
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 Docker’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:
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.