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.
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.
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.
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.
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.
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.
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
How do you install Docker Desktop for Windows?
Using the docker install
command in WSL
Downloading it from the Docker website and following the installation.
Enabling WSL integration in Docker.
Pulling a Docker image.
Free Resources