How to run a Windows container inside Windows Subsystem for Linux

The Windows Subsystem for Linux (WSL) is a versatile tool that grants you the ability to run a Linux environment directly on your Windows machine, eliminating the necessity for a virtual machine. But what if your requirements include running a Windows container within WSL? Although it may initially appear intricate, the task is entirely feasible with proper guidance. Let's look at the procedure for achieving this.

Setting up WSL

To begin, WSL needs to be installed. To accomplish this, you have to open PowerShell as an Administrator and input the following command:

wsl --install

By executing this command, WSL, along with the Ubuntu distribution, will be installed by default.

Docker desktop installation

The subsequent step involves installing Docker Desktop for Windows. Docker Desktop encompasses Docker Engine, Docker CLI client, Docker Compose, Notary, Kubernetes, and Credential Helper. You can fetch it from the Docker website and adhere to the installation guidelines.

Enable WSL integration

Following the successful installation of the Docker Desktop, you are required to activate WSL integration. To do so, open Docker Desktop, navigate to Settings > Resources > WSL Integration, and allow integration with your Linux distribution.

Enabling WSL Integration
Enabling WSL Integration

Pull a Windows docker image

At this stage, you are able to retrieve a Windows Docker image. Access your WSL terminal and input the subsequent command:

docker pull mcr.microsoft.com/windows/nanoserver:1809

By executing this command, the Windows Nano Server image will be pulled.

Run the Windows container

Finally, you can run the Windows container with the following command:

docker run -it mcr.microsoft.com/windows/nanoserver:1809 cmd

The above command initiates the Windows Nano Server container and opens a CMD prompt.

Conclusion

The process to run a Windows container within WSL entails the installation of WSL, Docker Desktop, activation of WSL integration in Docker, retrieval of a Windows Docker image, and initiating the Windows container. By following these steps, you can harness the capabilities of WSL and Docker to run Windows containers directly on your Windows device.

Review

1

How do you install Docker Desktop for Windows?

A)

Using the docker install command in WSL

B)

Downloading it from the Docker website and following the installation.

C)

Enabling WSL integration in Docker.

D)

Pulling a Docker image.

Question 1 of 40 attempted
Copyright ©2024 Educative, Inc. All rights reserved