Most organizations are looking at running containers in their organization. However, much of what you read about containers revolves around Linux containers. However, what if you want to run containers on Windows Server? Windows Server Containers are a great way to run Windows applications with an extremely small footprint. However, since Windows containers require a Windows container host, we need to use a Windows Server container host to install Docker so we can run Docker containers using Windows Docker images. Windows Server 2022 is the latest Windows Server operating system from Microsoft that enables running Docker containers. Let’s look at how to install Docker on Windows Server 2022 and see the steps involved.
Table of contents
- What is Docker Engine and Docker Desktop?
- What are container images?
- Why run Docker containers on Windows Server?
- Windows Server 2022 containers new features
- Solving docker container image kernel limitations
- Windows Server 2022 – Process isolation mode and Hyper-V isolation
- Install Docker on Windows Server 2022
- Install DockerMsftProvider and install Docker
- Wrapping Up
Check out the video of the process if you would rather see it in video form:
What is Docker Engine and Docker Desktop?
Both the Docker engine and Docker desktop are widely used in the enterprise to run business-critical container image applications. Docker provides the container runtime that allows the container image applications to run on top of the physical host machine.
The process to install Docker Desktop is performed using the Docker Desktop installer and makes getting up and running with Docker containers very easy using the Docker Desktop application.
You can also interact with Docker using the command prompt or a PowerShell session to run Docker command parameters from the command prompt. Both the Docker Desktop and Docker command prompt environments require a Docker installation on your Windows Server host.
What are container images?
A container image is an image of all the requirements it takes to run an application. A container image are much lighter weight than full virtual machine. Virtual machines are full operating system installations
Why run Docker containers on Windows Server?
You may wonder why you would want to run Docker containers on Windows Server containers. One reason is that to run Windows Containers, you need to run Windows containers on Windows Server. This requirement is because containers share the kernel of the container host. So you can’t run Linux Containers on Windows Server and Windows containers on Linux.
Windows Server 2022 containers new features
Windows Server 2022 offers new container features that provide a great way to run Docker containers with the latest features and enhancements when compared to older Windows Server versions, such as Windows Server 2016. What are some of the new Windows Server 2022 container features?
Server 2022 Core image size reduction
The container image size is extremely important. The smaller the container image, the faster, more agile, and easier it is to run the containers. In Windows Server 2022, the Server Core container image RTM layer at GA is 2.76 GB uncompressed. This is a major improvement over Windows Server 2019 which was 3.47 GB uncompressed container size. It represents a 33% smaller footprint.
Longer support cycle for Windows Server 2022 container images
Five years of support and an additional five years of extended support is now offered for all Windows server 2022 containers.
Virtualized time zone
Windows Server 2022 containers support virtualized time zone configuration separate from the host. This virtualized time zone support is included in the instance for each container.
You can use Group Managed Service Accounts with Windows containers to use Active Directory authentication.
IPv6 is now supported with Kubernetes in Windows.
Improved Kubernetes experience
Microsoft is continuing to improve the Kubernetes implementation with Windows containers. Windows Server 2022 provides more restrictive subnets and multiple subnets for each Windows worker node.
Solving docker container image kernel limitations
You can solve some of these limitations by running a container host as a virtual machine. Regardless of whether the physical host is running Windows Server or Linux, you can run a hypervisor such as Hyper-V or Linux with Proxmox, XCP-NG, KVM, etc to run virtual machines of either variety.
You can also use nested virtualization if you want to have the capabilities of a Windows hypervisor or Linux hypervisor, regardless of what operating system your physical host is running. However, you must have enabled nested virtualization to benefit from this capability.
Windows Server 2022 supports WSL installed
Now, with Windows Server 2022, you can have WSL installed in a supported way without any hacks to get it to work. This provides another way to work with Linux containers using your Windows Server 2022 host.
Windows Server 2022 – Process isolation mode and Hyper-V isolation
Running containers with Process Isolation mode is the traditional way that containers run. Even though they share the host operating system kernel, each container is isolated through namespace, resource control, and other process isolation technologies.
One of the cool benefits of running Docker container images on Windows Server 2022 with Hyper-V isolation is the added security benefits from the Hyper-V role. The Hyper-V isolation mode offers enhanced security.
In isolation mode, each container runs inside of a highly optimized virtual machine that effectively gets its own kernel. This isolation enables hardware-level isolation between each container and container host.
Install Docker on Windows Server 2022
The process to install Docker on Windows Server 2022 will include the following steps:
- Install the Windows Server 2022 containers feature
- Install Hyper-V in Windows Server 2022
- Install DockerMsftProvider and Docker
- Pull Windows container image for Docker
- Run the Windows Docker image
Install the Windows Server 2022 containers feature
Using the features wizards found in Server Manager, we can install the containers feature in Windows Server 2022 to run containers natively in Windows. The process is fairly straightforward. Run the Add roles and Features Wizard from Windows Server 2022.
On the Features screen, place a check next to the Containers feature.
Confirm the installation.
The containers installation is successful. You will be prompted to reboot your Windows Server 2022 host.
Install Hyper-V Role in Windows Server 2022
Next, for using Hyper-V isolation, we will need to have the Hyper-V role installed. Let’s quickly look at the Hyper-V role installation. On the Server Roles screen in Server Manager, place a check next to the Hyper-V role. Note you can also use the new Windows Admin Center to install roles in your Windows Server 2022 machine.
It will bring up the Add features that are required for Hyper-V.
Now we have the check placed next to Hyper-V, click Next.
Next, there will be a few screens of Hyper-V specific configuration.
You can go ahead and create the default Hyper-V virtual switch.
Decide if you want to allow live migration.
Configure the default storage location for Hyper-V virtual machines. Here, I am accepting the default settings.
Confirm the installation of the Hyper-V role and role features.
You will be prompted to reboot after the role is successfully installed.
Install DockerMsftProvider and install Docker
***Note*** DockerMsftProvider is now deprecated. However, leaving the below for posterity
Use the command found in the documentation here instead:
Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/Windows-Containers/Main/helpful_tools/Install-DockerCE/install-docker-ce.ps1" -o install-docker-ce.ps1
Deprecated steps below:
Next, we will install the Docker provider and install Docker itself. We can use just a couple of commands from the Powershell session to install the module and package needed. We need to be in an administrator prompt. The order of operations is we need to first install the Provider and then we can install Docker from the provider.
Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
This command will prompt you to install the Nuget provider in order to install the module.
To install Docker, we can use the following command:
Install-Package -Name docker -ProviderName DockerMsftProvider
You will see the message that the package is not marked as trusted. You will need to allow the installation.
Next, we need to restart Windows Server 2022. You can do that from the PowerShell session using the Restart-computer cmdlet.
Pull Windows Container image for Docker
After the Server 2022 host reboots, we can pull the Windows container image in a PowerShell session or Windows Command Prompt:
docker pull mcr.microsoft.com/windows/servercore:ltsc2022
Run the Windows Docker Image
Finally, let’s run the Windows Docker image in Windows Server 2022. This is a simple Docker run command. You can first list out your images using the docker images ls command and then run the container interactively with the following:
The process of installing Docker in Windows Server 2022 is straightforward. We just need to install a role and feature and then pull the module and package from the command line. After that, we can successfully pull the latest Docker image for Server Core and then run our container. From this point forward, it is straightforward to run your Docker containers in Windows.