Unlocking the Power of WSL2: Developing Big Microservices Systems on Windows

Anton Shcherbyna
5 min readMar 22, 2023

--

In the world of microservices, Linux has become the operating system of choice for running production services. Linux provides a stable, efficient, and scalable platform for running microservices, and it’s no surprise that most microservices deployments today run on Linux. However, many developers still use Windows as their primary development environment, which can create challenges when it comes to testing and deploying microservices to a Linux environment.

That’s where WSL2 comes in. WSL2 provides a Linux environment on Windows, which makes it possible to develop, test, and deploy microservices on Windows, while still taking advantage of the efficiency and stability of Linux in production.

Two technologies that have become essential for developing microservices are Git and Docker. Git is a version control system that helps developers manage code changes, while Docker provides a containerization platform that allows developers to package their applications and dependencies into containers. However, Docker Desktop, the popular Docker platform for Windows and macOS, is not free for big companies. Fortunately, developers can still use Docker on Windows through WSL2.

Configuring a Linux Environment in WSL2 for Powerful Development on Windows

Here are some instructions for configuring a WSL2 development environment:

  1. Install WSL2: The first step is to install WSL2 on your Windows machine. You can do this by using Microsoft guidelines, which is just running a few simple commands in Powershell.
wsl --install
wsl --install Ubuntu-22.04
wsl # open installed ubuntu distro
cd ~ # open home fodler

2. Install Git in WSL2: You can do this by running the following command in the wsl2 Linux environment:

sudo apt update -y && sudo apt upgrade -y && sudo apt-get install -y git
git version

3. Install Docker in WSL2: Before starting, you need to remove the Docker desktop then you can install by running the following command in the wsl2 Linux environment:

curl -s https://raw.githubusercontent.com/khdevnet/wsl2-env/main/install-docker.sh | sh

Note: After installation restart the ubuntu distro and test docker using the command:

wsl --shutdown # restart distro
wsl # open linux distro
docker run hello-world # test docker installation

4. Install dotnet7: You can do this by running the following command in the wsl2 Linux environment.

curl -s https://raw.githubusercontent.com/khdevnet/wsl2-env/main/install-dotnet7.sh | sudo bash

5. Install vscode: In addition, you may also want to install vscode to work with a code in the wsl Linux environment. It installed on windows, you can do this using the installer from their official website

6. Install vscode wsl extensions: To work with code located in wsl vscode has a list of extensions that could be installed using the guideline

7. Clone git repository with code: Finally you can clone git repository and start development on linux using vscode.

wsl # open wsl distro in powershell
# run commands in wsl linux shell
mkdir ~/projects
cd ~/projects
git clone https://github.com/khdevnet/httpvsgrpc.git
cd ~/projects/httpvsgrpc
code .

These steps will help you configure a powerful and free development environment for building microservices on Windows using Git, dotnet 7, and Docker.

However, real microservices projects are more complex than just one set of tools. Other microservices may use different languages like C++ or Go and may require a variety of additional tools.

To address this issue, you can create a Linux distribution base image that contains basic configurations such as VPN settings, Git, and more. This image can serve as a base for other development environments. Another benefit of using an image is that it allows you to back up your configurations while experimenting with different sets of tools.

Creating a Reusable Base Linux Image for a variety of Development Environments

Here are some instructions for creating a base image for the development environment:

  1. Get the name of installed distros: Run commands in Powershell. The command will print a list of all installed distros.
wsl -l

2. Export the distro image to the folder: Run commands in Powershell. The file c:/wsl/images/ubuntu2204.tar will be your base image with predefined tools.

wsl --export Ubuntu c:/wsl/images/ubuntu2204.tar

3. Create a new distro from the base image: Run commands in Powershell. The command will create a distro with the name UbuntuV2 using an image from the file c:/wsl/images/ubuntu2204.tar and will run it from the folder c:/wsl/instances/ubuntu2204

wsl --import UbuntuV2 c:/wsl/instances/ubuntu2204 c:/wsl/images/ubuntu2204.tar

4. Login to Installed ubuntu. Now you can open a new ubuntu distro shell with a user account.

wsl -d UbuntuV2 -u ant

Conclusion words

Using WSL2 with a base image for creating development environments can be a good solution with many benefits, such as consistency, easy backup, and fast setup. However, for larger microservices projects, this may not be the most efficient way of managing development environments.

To address this issue, the industry is moving towards creating remote development environment tools and the possibility of running development environments in Docker containers. These solutions allow developers to access their development environments from anywhere, collaborate more easily, and work with complex environments that are difficult to reproduce locally.

JetBrains is Space is a complete platform for team collaboration and development. It includes tools for project management, code review, continuous integration, and more. Space also includes a remote development environment feature that allows developers to work on projects in a secure, isolated environment that can be accessed from anywhere. JetBrains Fleet IDE is a cloud-based IDE that allows developers to access their development environment from anywhere. It includes a powerful code editor, debugging tools, and integration with Git and other version control systems.

GitHub has also entered the remote development space with its GitHub Codespaces feature. This allows developers to create development environments in the cloud that can be accessed directly from the GitHub web interface or from Visual Studio Code. GitHub Codespaces includes a variety of preconfigured development environments for different programming languages and frameworks.

--

--

Anton Shcherbyna

Senior/Lead/Azure Certified .NET Developer with hands-on experience in setup Testing, DevOps, CI/CD best practices for microservices architecture