- How to change the PowerShell prompt - Wed, Mar 22 2023
- Trim characters from strings in PowerShell - Tue, Mar 14 2023
- Set Chrome, Firefox and Edge as default mail client (mailto handlers) - Mon, Mar 6 2023
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.
After starting Docker, open the settings via the tray applet and make sure Use the WSL 2 based engine is 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.
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.
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.
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!
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.
Want to write for 4sysops? We are looking for new authors.