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.
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.