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.
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
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
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.
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.
Now, let’s pull the Windows Server 2016 Nano Server image as the base image for working with containers.
docker pull microsoft/nanoserver
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
Using docker info, you can see a wealth of information about Docker and containers.
The docker stats command allows see the utilization statistics of your Hyper-V containers.
Using docker container ls, you can list out the containers on the system, when created, status, etc.
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.
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.