« Previous 1 2 3 Next »
Use Linux Containers with WSL2 on Windows
Nested
Docker with WSL
To use Docker containers on a computer with Windows 10 and WSL, first download the free Docker Desktop for Windows [2] container solution. During the install, the Docker configuration opens, and you can enable the Install required Windows components for WSL2 option. The settings can also be configured from the Docker tray icon later.
After the install, click on the icon in the tray area to open Docker. Various menu items are available, including Settings
. You need to enable the Use the WSL 2 based engine
option in the General dialog (Figure 1). Docker administration is also subject to a permissions structure in Windows 10. Users who need to manage Docker must be members of the local docker-users
group. You can call local user management by typing lusrmgr.msc
. By default, the user who installed Docker on the machine is already a member. Additionally, you need to check that the Docker Desktop Service has been started.
Use the Resources item to select which of the installed distributions you want to use for container operation under WSL Integration . By default, this is the first distribution you installed. Under Network , you can specify which subnet Docker uses for its containers and which DNS servers you want to use.
Launching Containers with WSL and Docker
To start Docker containers, call Windows Terminal or Command Prompt and display the distributions by typing:
wsl -l -v
Docker now appears, as do the installed distributions. For example, to use Ubuntu, run Ubuntu with the wsl -d ubuntu
command and open Linux Bash for the distribution. To test Docker with WSL, download a sample container by typing, for example:
docker run -dp 80:80 docker/getting-started
On first launch, Docker fails to find the image locally and downloads it from Docker Hub. To start another sample container that displays information about its operation, try
docker run hello-world
Again, the necessary files and image for the container are downloaded automatically. When downloading and starting containers, a message from the Windows Defender firewall sometimes appears (Figure 2). You have to allow access.
Once the container is running properly, open a web browser on the computer and enter the local host address. Port 80 of the host is mapped to port 80 in the container. The sample container uses the Nginx web server in the container and displays a tutorial for Docker right after you access the web page.
From the command prompt or in PowerShell in Linux Bash of the Ubuntu distribution, you can then control the container and Docker in the Windows terminal. Various commands are available for managing the containers.
Managing Docker and Containers
In WSL, you can fire up additional containers on Ubuntu after the installation, and you have various commands at your disposal (Table 2).
Table 2
Docker Commands
Command | Function |
---|---|
docker -version
|
Display the installed Docker version. The version should be reported without an error message. If you see an error message, Docker is not working. |
docker search <name>
|
Search for images on Docker Hub. The container host will need a connection to the Internet. |
docker ps -a
|
View a list of all containers on a container host. |
docker images
|
List the existing images on the container host. |
docker login
|
Log in to Docker Hub in the terminal. |
docker inspect <ID>
|
Retrieve extended information for containers, not least the IP address of the container. |
Of course, you can create and edit your own images, for example, on the basis of existing containers:
docker commit <ID> <folder>/<container image>
One example is:
docker commit 662f25d6d835 joos/joosimageweb
Besides using the terminal, you can also manage containers in WSL from the Docker Desktop graphical interface. You can view the started containers and their statuses in Containers/Apps . If you mouse over the container name, Docker displays icons for controlling the container on the right.
You can use the icons to switch to the container's command-line interface (Figure 3) and restart, terminate, or delete the container. If you click on a container, you can also view its logs. The Inspect
item gives you the same information that you can also display onscreen by typing docker inspect <ID>
. Stats
shows you the container's resource consumption.
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)
Buy ADMIN Magazine
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Most Popular
Support Our Work
ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.