Version 2 of WSL not only offers a new architecture based on a virtual machine, a proprietary Linux kernel, and a native EXT4 file system, but also a closer integration with Docker. In this way, Linux containers can be used very easily in the context of Windows.

Containers package applications together with the system services or libraries on which they rely. This also includes a separate instance of the file system. This simplifies and accelerates deployment because applications bring their own environment with them and therefore do not depend on a specific configuration of the host system.

Docker has established itself as the market leader. It defines the packaging format for containers, and together with Docker Hub, also provides a repository for images. Kubernetes is becoming the standard for the management of several containers, including load balancing and failover.

Containers have been popular and more widespread in Linux than in Windows, as Windows did not receive appropriate support for containers until Server 2016. WSL 2 improves support for Linux containers by limiting resource consumption (RAM, CPU usage) to what is actually needed and by increasing overall performance.

The wide range of ready-made container images for Linux allows the provision of various services in the context of Windows. This applies, for example, to databases, web servers, or the entire LAMP stack, which no longer needs to be installed in the OS in the conventional way.

Preparing WSL 2 for Docker ^

If you have not already done so, the first step is to install the subsystem for Linux under Windows 2004, Server 2004, or a newer version (see my instructions). WSL is configured for version 1 by default. Therefore, after adding a distribution via the Microsoft Store, you should check whether a conversion to WSL 2 is required. This can be verified using:

wsl -l -v

With the parameters --set-default-version <version> or -s <Distro> <version>, wsl.exe can set version 2 as the default or force it to be used for a specific Linux distribution.

Installing Docker Desktop ^

Now it's time to install Docker Desktop for Windows. You have to first download the software from the manufacturer's website, and then you can run the setup. If you only intend to run Linux containers in the context of WSL 2, you do not have to activate the Windows container feature.

Installation of Docker for Windows—the components for WSL 2 should be selected

Installation of Docker for Windows—the components for WSL 2 should be selected

After starting Docker, open the settings via the tray applet and make sure Use the WSL 2 based engine is enabled.

The setting for the WSL 2 engine must be enabled

The setting for the WSL 2 engine must be enabled

If you try to run Docker as a standard user, it will fail due to missing permissions. Therefore, you need to add accounts that are supposed to run Docker to the docker-users local group. By default, this group contains only the admin user who has installed Docker.

Users who should have the right to run Docker must be members of the docker users group

Users who should have the right to run Docker must be members of the docker users group

Before you start a container in a WSL 2 distribution, you should check the Docker settings under Resources > WSL integration to see whether Docker is activated for the desired Linux. Generally, this is only the case for the default distribution.

Activating Docker for the desired distributions

Activating Docker for the desired distributions

Executing the container ^

If this condition is also met, then you can start the Linux distribution, such as Ubuntu 18.04, using

wsl -d ubuntu-18.04

To create a first container and to check the functionality of the installation, Docker offers some sample images. For example, the command

docker run -dp 80:80 docker/getting-started

creates a container that includes an nginx web server, which serves the Docker documentation.

Running a simple container with the Docker documentation

Running a simple container with the Docker documentation

You can connect to it either by calling up http: // localhost (because port 80 has been mapped to the host's port 80 in this case) in your Windows browser or by opening the Unix shell in the container. Both actions can be initiated using the corresponding icons in the Docker console. For the CLI, you do not need to call docker exec with the container ID thanks to this shortcut.

Subscribe to 4sysops newsletter!

Starting the shell in the container via the Docker GUI

Starting the shell in the container via the Docker GUI

Besides such simple applications, there are numerous ready-to-run images that you can download using the docker command and start immediately in the container. Among them are also complete LAMP stacks.

+1
0 Comments

Leave a reply

Please enclose code in pre tags

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2021

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account