Installing and Configuring Windows Server 2016 Hyper-V Containers

Containers are certainly all the rage in the world of virtualization and are the next evolution in how businesses deploy and host applications and perform development. Containers offer several advantages over full blown virtual machines when it comes to efficiency, footprint, and overall complexity. In the world of Windows Server, with Windows Server 2016, there are now two different ways to deploy and consume containers – Windows Server containers and Hyper-V containers. In this post we will take an overall look at the differences between the two as well as Installing and Configuring Windows Server 2016 Hyper-V containers to see the process involved as well as the points to keep in mind with deployment.

Windows Server Containers and Hyper-V Containers Differences

You might first ask – why are there two options in deploying containers in a Windows Server environment?  The answer basically comes down to isolation.  The whole premise of what makes a container work, can also post some security doubts or questions among organizations who may want to deploy containers in a tradition sense.  Containers make use of the “container host” operating system kernel for all the containers that exist on the container host.  This plays a large part in why the footprint is so small with containers.  All of the host operating system requirements are provided by the host and the application requirements and environment are contained and provided in the container itself.  Containers provide what is called user mode isolation.
For some organizations however, this level of isolation is not enough, especially if organizations are hosting container environments for multiple tenants.  Also, for many businesses who want to host containers in Azure, having further isolation is required.  This is where Hyper-V containers come into play.  With Hyper-V containers, virtual machines are used to host the container environment.  This way, the container does not share the Hyper-V host kernel with all the other containers.  The container uses the kernel of the nested container host that it is provisioned by in Hyper-V.
Nested virtualization that makes Hyper-V containers possible was introduced with Windows Server 2016 Hyper-V functionality.  This is a reason why Hyper-V container support is

Installing and Configuring Windows Server 2016 Hyper-V containers

Let’s take a look at installing and configuring Windows Server 2016 Hyper-V containers and the steps involved to do this.  In most enterprise environments using Hyper-V to run production workloads, Hyper-V will be running on top of a Windows Server Failover Cluster.  There are a few considerations to be made when considering containers on Hyper-V clusters:
  • Containers are not natively clustered in Windows Failover Clustering, the way a VM can be clustered.
  • They can run inside a clustered VM but can’t be clustered in and of themselves at least in Windows Server 2016.  No doubt in future Windows Server releases this will be a capability
  • Containers can’t be Live Migrated like virtual machines
The first thing to be considered are the Windows Roles and Features.  If you are enabling container support on a Hyper-V Server that already exists, you will already have the Hyper-V role installed.  However, there is an additional Containers feature that needs installed also.  This can be done with either PowerShell or using the Server Manager.
Below, we are using PowerShell to install the needed components for Docker which will also install the Containers Windows Feature as well.
Installing-and-Configuring-Hyper-V-Containers-Hyper-V-role-installed Installing and Configuring Windows Server 2016 Hyper-V Containers
Installing and Configuring Hyper-V Containers Hyper-V role installed
Containers-Feature-needs-enabled-when-installing-and-configuring-Hyper-V-containers Installing and Configuring Windows Server 2016 Hyper-V Containers
Containers Feature needs enabled when installing and configuring Hyper-V containers
Using PowerShell here, we need to install both the Module and Package for the Microsoft Docker Provider.  First below, installing the Module for “DockerMsftProvider”.  Note below, you will need to approve the installation of the NuGet provider. 
Install-Module -Name DockerMsftProvider -REpository PSGallery -Force
Install-Microsoft-Docker-Provider-Module-Installing-and-Configuring-Windows-Server-2016-Hyper-V-containers Installing and Configuring Windows Server 2016 Hyper-V ContainersInstall Microsoft Docker Provider Module Installing and Configuring Windows Server 2016 Hyper-V containers
Next, we install the DockerMsftProvider Package.  This is where the actual Containers Feature gets enabled as is noted by the reboot prompt. 
Install-Package -Name docker -ProviderName Docker -ProviderName DockerMsftProvider
Install-the-Microsoft-Docker-Provider-Package-in-Windows-Server-2016-Hyper-V Installing and Configuring Windows Server 2016 Hyper-V Containers
Install the Microsoft Docker Provider Package in Windows Server 2016 Hyper-V
We can additionally see this if you look at Server Manager to verify the Containers Feature was added.  As you can see below, the Containers Features shows Installed and we see the pending restart message.
Hyper-V-Containers-Feature-has-been-added-reboot-pending-in-Windows-Server-2016 Installing and Configuring Windows Server 2016 Hyper-V Containers
Hyper-V Containers Feature has been added reboot pending in Windows Server 2016
After rebooting, you can verify that Docker has been installed.  You can easily do this by typing docker at the PowerShell command prompt.  As you can see we have a response from the docker command showing our available options.
Verifying-Docker-is-installed-in-Windows-Server-2016 Installing and Configuring Windows Server 2016 Hyper-V Containers
Verifying Docker is installed in Windows Server 2016
Now, let’s pull the Windows Server 2016 Nano Server image as the base image for working with containers. 
docker pull microsoft/nanoserver
Use-Docker-to-Pull-down-the-Windows-Server-2016-Nano-Server-container-base-image Installing and Configuring Windows Server 2016 Hyper-V Containers
Use Docker to Pull down the Windows Server 2016 Nano Server container base image
Once the Nano Server image has been pulled down, you can spin up a new container using the Nano Server image. 
docker run -i --isolation=hyperv microsoft/nanoserver cmd
Creating-a-new-Hyper-V-Container-in-Windows-Server-2016-with-docker Installing and Configuring Windows Server 2016 Hyper-V Containers
Creating a new Hyper-V Container in Windows Server 2016 with docker
Using docker info, you can see a wealth of information about Docker and containers.
Taking-a-look-at-Docker-info-command-in-Windows-Server-2016-Hyper-V-to-see-running-container-count Installing and Configuring Windows Server 2016 Hyper-V Containers
Taking a look at Docker info command in Windows Server 2016 Hyper-V to see running container count
The docker stats command allows see the utilization statistics of your Hyper-V containers.
See-Hyper-V-Container-utilization-using-Docker-stats-in-Windows-Server-2016 Installing and Configuring Windows Server 2016 Hyper-V Containers
See Hyper-V Container utilization using Docker stats in Windows Server 2016
Using docker container ls, you can list out the containers on the system, when created, status, etc.
Listing-Windows-Server-2016-Hyper-V-containers-with-docker-container-ls-command Installing and Configuring Windows Server 2016 Hyper-V Containers
Listing Windows Server 2016 Hyper-V containers with docker container ls command
To get rid of a container, you can list out the containers, then use the docker container kill <container ID> command.  As you see below, after killing the container, running a docker container ls shows no containers running.
Killing-a-Windows-Server-2016-Hyper-V-Docker-Container Installing and Configuring Windows Server 2016 Hyper-V Containers
Killing a Windows Server 2016 Hyper-V Docker Container

Takeaways

As you can see, Installing and Configuring Windows Server 2016 Hyper-V containers is fairly straightforward.  It involves installing the components required from a Windows Server perspective (Hyper-V and containers role and feature respectively).  Additionally, you have to pull down the Windows Server base image that will serve as the container host in the nested Hyper-V configuration.  There are a number of great Docker commands that allow working with and seeing Hyper-V container information.  Stay tuned for more Hyper-V container related posts.

Post a Comment

0 Comments