Getting Started with Containers (Part 3)

by [Published on 19 May 2016 / Last Updated on 19 May 2016]

This article continues the discussion of Windows Server containers by walking you through the process of deploying a container image.

If you would like to read the other parts in this article series please go to:

Introduction

In the previous article in this series, I spent some time talking about container hosts and images. Before I show you how to create a container, I wanted to spend a bit more time talking about images. The reason for this is that images are probably the single most important concept to understand with regard to containers.

Container Portability

So far, I have been approaching the subject of containers from the standpoint of resource conservation. Indeed, containers can be more efficient than traditional virtual machines. However, there is another important reason for using containers. Container images are portable.

In recent years, there has been a lot of discussion around being able to move applications between the datacenter and the cloud. Container images can make this much easier to achieve. Container images can also be helpful if your organization develops its own applications, because they can help to prevent situations in which an application works in a development environment, but crashes once it is moved to the production environment. A container image is similar to a portable application. A developer can containerize their application, and give it to an administrator who can run that application on any Windows-based container host, regardless of whether it exists locally or in the cloud.

Keep in mind however, that container image portability does have its limits. Although I have never tried it myself, I have read several blog posts indicating that Windows containers cannot be run on Linux hosts, and that Linux containers cannot be run on Windows hosts.

The Anatomy of a Container

Windows Server containers make use of two different types of images. There are Base OS Images and Container images. The Base OS images are essentially just an operating system. The nice thing about these images is that you do not have to create them from scratch. You can download the base OS image from Microsoft. The other type of image is a container image. The container image is your own custom image. The container image is based on a base OS image, but does not contain a full blown OS itself.

Installing Windows Containers

As previously noted, containers can be used either at the Windows Server level or at the Hyper-V level. For the purpose of this article, I will be deploying Windows Server containers. So with that said, the first thing that must be done is to install the Containers feature and then reboot the server. The easiest way to accomplish this is to open an elevated PowerShell window and then enter the following commands:

Install-WindowsFeature Containers

Shutdown /R

The Containers feature can of course be installed using Server Manager’s Add Roles and Features wizard, but Microsoft really seems to envision using Server Core or even Nano Server as a container host. That’s why I am providing PowerShell-based instructions.

Once the system reboots, then you can verify that it is configured to act as a container host by entering the Get-ContainerHost cmdlet into PowerShell. The output should resemble what you see in Figure A.

Image
Figure A:
 You can use the Get-ContainerHost cmdlet to make sure that the Containers feature is installed.

The next thing that you will have to do is to create a virtual switch. The concept of virtual switches should already be familiar to administrators who have experience managing Hyper-V. In a Hyper-V environment, the virtual switch is what provides network connectivity to a virtual machine. Typically, a virtual machine will contain one or more virtual NICs, and those virtual NICs will connect to a virtual switch. Similarly, virtual switches provide connectivity to containers.

The most typical type of virtual switch used by containers is NAT. Think of a NAT switch as a virtual representation of a physical NAT device. When you create your NAT switch, you are going to need to define a subnet for use with the NAT environment. In looking at several Websites, many people seem to be using the 172.16.0.0/12 subnet. Since this seems to be a popular choice, I will go ahead and use it too.

In order to create a NAT virtual switch and provision the NAT environment, there are two commands that you will have to enter. Given a subnet of 172.16.0.0/12, these commands are:

New-VMSwitch –Name “My Virtual Switch” –SwitchType NAT –NATSubnetAddress “172.16.0.0/12”

New-NetNat –Name MyNAT –InternalIPInterfaceAddressPrefix “172.16.0.0/12”

You can see what this looks like in Figure B.

Image
Figure B: I have defined a new virtual switch.

The next thing that we have to do is to install a base OS image. Remember, we can’t create any custom containers unless we first have a base OS image in place. Microsoft provides base OS images that are based on Windows Server Core, and on Nano Server. The thing is however, that these base OS images do not exist by default. We have to install them.

There is nothing difficult about installing the container base OS images, but the process might be a little bit different from what you would expect. The cmdlet used to download and install a base OS image is Install-ContainerImage. Using this command is simple enough, but we can’t use the command just yet. Before we can install a container image, we have to figure out which container images are available, and before we can do that, we have to install a package provider called ContainerProvider. It is this package provider that lets us access to container images.

To install the package provider, enter the following command:

Install-PackageProvider ContainerProvider –Force

Once the container provider is installed, you can determine which container images are available by entering this command:

Find-ContainerImage

Now, you just have to download and install the image or images of choice. As previously mentioned, you can do this by using the Install-ContainerImage command. You will have to specify the container image’s name and version number. The Find-ContainerImage command provides this information. For example, if you look at Figure C, you can see that there is an image named NanoServer. Its version is 10.0.10586.0. If I wanted to install this container image, I would use this command:

Install-ContainerImage –Name NanoServer –Version 10.0.10586.0

Image
Figure C: I have installed the Nano Server container.

In case you are wondering, you can have multiple base OS images. If you look at Figure D for example, you can see that I have installed Nano Server and Windows Server Core as base OS images. A container only needs one base OS image, but you can install multiple images.

Image
Figure D: I have installed Nano Server and Windows Server Core as base OS images.

Conclusion

As you can see, it’s pretty easy to configure Windows Server 2016 to act as a container host and to download and install base OS images. In the next article in this series, I will begin showing you what types of things we can do with these images. In the meantime, if you would like to skip ahead then Microsoft provides some excellent documentation. This is the same documentation that I am working from while developing this article series.

If you would like to read the other parts in this article series please go to:

See Also


The Author — Brien M. Posey

Brien M. Posey avatar

Brien Posey is an MCSE and has won the Microsoft MVP award for the last few years. Brien has written well over 4,000 technical articles and written or contributed material to 27 books.

Advertisement

Featured Links