Windows Containers

Installing and Configuring Windows Server 2016 Hyper-V Containers

A look at Installing and Configuring Windows Server 2016 Hyper-V Containers along with the requirements, pulling base images, and Docker commands

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 Hyper-V Containers Hyper-V role installed
Containers-Feature-needs-enabled-when-installing-and-configuring-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-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
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
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
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
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
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
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
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
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
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.

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.