Install Docker in Windows Server 2019
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
- 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.
- Install Windows Server 2019 containers feature
- Install Hyper-V
- Install DockerMsftProvider and latest Docker version
- Pull Docker images
- 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.
You will need to reboot after the feature installation, or optionally select to reboot automatically after the feature is installed.
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.
You can also easily install Hyper-V using PowerShell with the following command:
Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Restart
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:
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
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
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.“
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
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.