Windows Server 2022

Install Docker on Windows Server 2022

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.

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.

Application compatibility

You can use Group Managed Service Accounts with Windows containers to use Active Directory authentication.

IPv6 support

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:

  1. Install the Windows Server 2022 containers feature
  2. Install Hyper-V in Windows Server 2022
  3. Install DockerMsftProvider and Docker
  4. Pull Windows container image for Docker
  5. 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.

Beginning the Add Roles and Features wizard
Beginning the Add Roles and Features wizard

On the Features screen, place a check next to the Containers feature.

Installing the containers feature
Installing the containers feature

Confirm the installation.

Confirm the containers installation
Confirm the containers installation

The containers installation is successful. You will be prompted to reboot your Windows Server 2022 host.

Successful installation of the containers feature in Windows Server 2022
Successful installation of the containers feature in Windows Server 2022

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.

Place a check next to the Hyper V role
Place a check next to the Hyper V role

It will bring up the Add features that are required for Hyper-V.

Add the Hyper V remote administration tools
Add the Hyper V remote administration tools

Now we have the check placed next to Hyper-V, click Next.

Role and remote administration tools selected
Role and remote administration tools selected

Next, there will be a few screens of Hyper-V specific configuration.

Beginning the wizard to configure the Hyper V Role
Beginning the wizard to configure the Hyper V Role

You can go ahead and create the default Hyper-V virtual switch.

Create the default Hyper V Virtual Switch
Create the default Hyper V Virtual Switch

Decide if you want to allow live migration.

Allow Virtual Machine migration
Allow Virtual Machine migration

Configure the default storage location for Hyper-V virtual machines. Here, I am accepting the default settings.

Default virtual machine storage configuration
Default virtual machine storage configuration

Confirm the installation of the Hyper-V role and role features.

Confirm the Hyper V role installation
Confirm the Hyper V role installation

You will be prompted to reboot after the role is successfully installed.

Reboot the server after installing the Hyper V role
Reboot the server after installing the Hyper V role

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
.\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.

Install the module needed to install Docker from the Nuget Provider
Install the module needed to install Docker from the Nuget Provider

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.

Installing Docker from the Nuget provider
Installing Docker from the Nuget provider

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
Pull the latest Windows Server 2022 LTSC image
Pull the latest Windows Server 2022 LTSC image

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:

List the Windows container images using docker images ls and running it interactively
List the Windows container images using docker images ls and running it interactively
Running commands inside the container
Running commands inside the container

Wrapping Up

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.

Subscribe to VirtualizationHowto via Email 🔔

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com and has over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, Brandon has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family.

Related Articles

6 Comments

  1. Thank’s for the very good guide.
    When i Pull Windows Container image for Docker, then i get always the error:

    “docker : Error response from daemon: Get “https://mcr.microsoft.com/v2/”: context deadline exceeded
    In Zeile:1 Zeichen:1
    + docker pull mcr.microsoft.com/windows/servercore:ltsc2022″

    Have anyone a idea ?
    My Proxy_Settings are correct.

    Thanks for Help.

  2. Hi,
    I don’t get your last statement “From this point forward, it is straightforward to run your Docker containers in Windows.”. How do you mean it? One runs containers in this Windows container? how?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.