Windows Containers

Install Docker in Windows Server 2019

Install Docker in Windows Server 2019 step-by-step. Install MsftDockerProvider, Docker, Containers feature, Hyper-V, and Server Core image

Want to play around with Windows Server Docker Containers? This is easy to do with only a few steps on a Windows Server 2019 host. Additionally, you may want to do more than play around. You may have a containerized application you want to deploy and run on a Windows Server container host. This post will look at how to install Docker in Windows Server 2019 and get an overview of the step-by-step approach to running containerized applications on your Windows Server 2019 hosts.

Modernized Windows applications with Windows Server and Docker

There is no question that businesses are looking to modernize their applications to be cloud native and run microservices instead of the traditional monolithic 3-tier legacy server applications. Native Docker containers on Windows Server and Windows Desktops provides many different use cases in your Windows environment. These include:

  • Containerized Windows apps – You might envision Docker being a more Linux native solution. However, Microsoft and Docker run and work well together due to a joint partnership between Docker and Microsoft. With the native Windows integration from Docker, developers can leverage Docker containers the same way that they do on Linux, using the same Docker CLI, API, and image format. There are additional benefits to running Docker containers in Windows, including Hyper-V isolation that provides an extra layer of security to your container instances. Microsoft also continues to reduce the size of the Windows Server Core and other Windows images for use with Docker, making the footprint even smaller.
  • Run both Windows and Linux nodes on the same cluster – Using Docker enterprise, organizations can run both Windows Server and Linux nodes on the same cluster. Hybrid applications may leverage both Linux and Windows components. With Docker Enterprise, Windows containers have access to the same features as Linux containers
Running-both-Linux-and-Windows-containers-in-the-same-cluster-1
Running both Linux and Windows containers in the same cluster
  • Modernize legacy Windows Server apps – Cobine Docker Enterprise platform with built-in tools to containerize legacy Windows applications.

Install Docker in Windows Server 2019

Let’s take a look at the steps required to install docker in Windows Server 2019. This includes a few steps that need to be taken to get the containers feature enabled as well as installing Docker and the container images. Let’s look at the following steps.

  1. Install Windows Server 2019 containers feature
  2. Install Hyper-V
  3. Install DockerMsftProvider and latest Docker version
  4. Pull Docker images
  5. Run a Docker image

1. Install Windows Server 2019 Containers feature

First, before running Docker images, we need to install the Windows Server 2019 containers feature. This installs and configures your Windows Server 2019 host for use with containerized workloads. This can easily be done using the Server Manager tool. Under Features, install Containers.

Install-the-containers-feature-in-Windows-Server-2019
Install the containers feature in Windows Server 2019

You will need to reboot after the feature installation, or optionally select to reboot automatically after the feature is installed.

Finishing-the-containers-feature-installation-with-a-reboot
Finishing the containers feature installation with a reboot

2. Install Hyper-V

If you plan to use Hyper-V isolation with your Docker containers (which I highly recommend for extra security), you will need to install the Hyper-V role. This is located under Server Roles > Hyper-V.

Enabling-Hyper-V-for-Hyper-V-isolation-for-Docker-containers
Enabling Hyper-V for Hyper-V isolation for Docker containers

You can also easily install Hyper-V using PowerShell with the following command:

Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart
Installing-the-Hyper-V-role-using-PowerShell-for-Hyper-V-isolation
Installing the Hyper-V role using PowerShell for Hyper-V isolation

3. Install DockerMsftProvider and latest Docker version

Next, we need to install DockerMsftProvider and the latest Docker version on our Windows Server 2019 host. To do this, run the following commands. To install the DockerMsftProvider, use:

Install-Module -Name DockerMsftProvider -Repository PSGallery -Force

Now, to install Docker:

Install-Package -Name docker -ProviderName DockerMsftProvider

After you have ran the above commands, reboot your Windows Server 2019 server. To use PowerShell, run the following:

Restart-Computer -force
Installing-the-MsftDockerProvider-and-Docker-1
Installing the MsftDockerProvider and Docker

4. Pull Docker Images

Let’s now look at pulling Docker images. This is straightforward and can be done from a PowerShell command line. To pull the LTSC Windows Server 2019 core image, use the following command:

docker pull mcr.microsoft.com/windows/servercore:ltsc2019
Downloading-and-extracting-a-Windows-Server-2019-Docker-image
Downloading and extracting a Windows Server 2019 Docker image

5. Run a Docker Image

To run a Docker image, we can do this using the following command. This will spin up a container to run a simple command.

docker run -it mcr.microsoft.com/windows/servercore:ltsc2019 hostname

If you want to run the container interactively, you will use the following command:

docker run -it mcr.microsoft.com/windows/servercore:ltsc2019
Interactive-Docker-image-running-and-listing-Docker-containers
Interactive Docker image running and listing Docker containers

Windows Docker Container Hyper-V Isolation

Windows Server 2019 Hyper-V isolation allows effectively running a container with boundaries so that the only kernel the container knows about is the Hyper-V VM container that it is provisioned inside of. This allows running multiple containers with a much higher degree of security when compared to running native Windows containers without the isolation so that the host’s kernel is shared between all running containers.

From Microsoft regarding the Hyper-V isolation mode:

This isolation mode offers enhanced security and broader compatibility between host and container versions. With Hyper-V isolation, multiple container instances run concurrently on a host; However, each container runs inside of a highly optimized virtual machine and effectively gets its own kernel. The presence of the virtual machine provides hardware-level isolation between each container as well as the container host.

Hyper-V-isolation-architecture-overview
Hyper-V isolation architecture overview
docker run -it --isolation=hyperv mcr.microsoft.com/windows/servercore:ltsc2019

Verifying Windows Server 2019 Docker Container Hyper-V Isolation

Using the command we can verify the Windows Server 2019 Docker Image Hyper-V isolation. Use the command below:

get-process -Name vmwp
Verifying-Windows-Server-2019-Hyper-V-container-isolation
Verifying Windows Server 2019 Hyper-V container isolation

Wrapping Up

The process to Install Docker in Windows Server 2019 is fairly straightforward to get Docker up and running. Windows Server 2019 provides many great features to run your Docker containers, including Hyper-V isolation for additional security and kernel protection. Also, Microsoft Windows Server 2019 can run both Windows and Linux containers meaning you can have a mixed environment supporting applications needing both Windows and Linux components. With each new Windows release including semi-channel releases, Microsoft is continuing to minimize the footprint of the Windows Docker images. These are getting smaller and more efficient.

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 a 7-time VMware vExpert, with over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, He 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. Also, he goes through the effort of testing and troubleshooting issues, so you don't have to.

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.