Home - About me - Browse by categories

Getting Started with Windows Containers

As you probably know, Microsoft announced the RTM of Windows Server 2016 two weeks ago during Microsoft Ignite. Since yesterday, the bits are available and you can start to work with this new version of Windows Server, that brings containers to the Windows ecosystem (and many more features that you can discover here).

This article will help you to get started with Windows Containers on Windows Server 2016 and Windows 10.

Get your environment ready

Windows Containers are available on Windows Server 2016 and Windows 10 Anniversary Update. There are several ways to get your environment ready.

Windows 10 Anniversary Update

The simple way to install and configure Windows Container features on your Windows 10 Anniversary Update machine is to download Docker for Windows. You need to work with the beta channel to get the support of Windows Container with Docker for Windows.

If you do not want use Docker for Windows, open an elevated PowerShell session and follow these steps:

Enable-WindowsOptionalFeature -Online -FeatureName containers -All
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
Restart-Computer -Force

Once restarted, re-open an elevated PowerShell session and install Docker using the following commands.

Invoke-WebRequest "https://master.dockerproject.org/windows/amd64/docker-1.13.0-dev.zip" -OutFile "$env:TEMP\docker-1.13.0-dev.zip" -UseBasicParsing
Expand-Archive -Path "$env:TEMP\docker-1.13.0-dev.zip" -DestinationPath $env:ProgramFiles
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\Docker", [EnvironmentVariableTarget]::Machine)
dockerd --register-service
Start-Service Docker

After this step, you should be able to work with Docker on your machine. You can type docker info to check that all is good.

Windows Server 2016

Docker for Windows does not work on Windows Server 2016, so you need to install the containers feature by yourself, but it’s really simple. Open an elevated PowerShell session and follow these steps:

Install-WindowsFeature containers
Restart-Computer -Force

Once restarted, re-open an elevated PowerShell session and install Docker.

Invoke-WebRequest "https://download.docker.com/components/engine/windows-server/cs-1.12/docker-1.12.2.zip" -OutFile "$env:TEMP\docker.zip" -UseBasicParsing
Expand-Archive -Path "$env:TEMP\docker.zip" -DestinationPath $env:ProgramFiles
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\Docker", [EnvironmentVariableTarget]::Machine)
dockerd.exe --register-service
Start-Service Docker

After this step, you should be able to work with Docker on your machine. You can type docker info to check that all is good.

Windows Server 2016 with Containers on Azure

If you do not want install and configure yourself Windows Server 2016 and the containers features, the best and quick way to get started is to use the Windows Server 2016 Datacenter with Containers image available in the Microsoft Azure Marketplace. You don’t have a Microsoft Azure account yet? Create one and try Azure for free now from http://aka.ms/tryazure.

Sign in to your Azure account on the portal and search for Windows Server 2016. In the list, you will find the image “ - with Containers”:

Gettings Started Windows Containers

Click on this image on the results list:

Gettings Started Windows Containers

Then click on Create to start the creation wizard:

Gettings Started Windows Containers

Configure the basic settings of your new virtual machine: name, type of disk, username, password and the region where you want to deploy this machine.

Gettings Started Windows Containers

Then click OK and choose the size of the virtual machine. Click OK when you have made your choice.

In the next step, the only mandatory option is the network. Click on the Virtual Network option and click Create New:

Gettings Started Windows Containers

Give a name to your network and the address space / range you want to work with. Click OK to validate.

Now, you should be able to validate the step 3 and click OK to start the deployment once the validation step completed:

Gettings Started Windows Containers

Wait for the deployment to be completed:

Gettings Started Windows Containers

Once deployed, click on the “Connect” button in the virtual machine general overview:

Gettings Started Windows Containers

It will launch an RDP session. Use your credentials to start a session. Open PowerShell and start the docker service using the following command:

Start-Service Docker

Once started, type docker info to validate that all is working as expected.

Pull the base container image

Now that you have a machine configured to work with Docker and Windows Containers you need to pull a base image. There are two base images available: Windows Server Core and Nano Server:

docker pull microsoft/windowsservercore
docker pull microsoft/nanoserver

Note: if you have deployed the pre-configured virtual machine in Azure, the two base images are already pulled.

Once completed, you can type docker image to check that the image is available on your machine:

Gettings Started Windows Containers

Hello Windows Containers

In this part, you will start your first Windows Container using Docker.

Open an elevated PowerShell session on the machine you have configured in the previous step and type the following command:

docker run -it microsoft/windowsservercore cmd

This command will start a new container using the Windows Server Core base image and start cmd.exe within the container. The -it option allows to start the container in interactive mode so you can be connected within the container and use CMD from the inside:

Gettings Started Windows Containers

Depending on whether you are running the previous command on Windows Server 2016 or Windows 10, you are not working with the same kind of Windows Containers.

If you start another PowerShell window and type docker ps you will see that a container is running:

Gettings Started Windows Containers

Actually, there are two types of Windows Containers:

Gettings Started Windows Containers

Windows Server Containers share the same base OS and kernel. Hyper-V containers have been designed to be more isolated that Windows Server Containers and are running directly on the hypervisor. They are not sharing the guest OS nor the kernel.

When running on Windows 10, you can only work with Hyper-V containers.

When running on Windows Server 2016, you can choose between Hyper-V and Windows Server containers. By default, when you use the docker run command it will start a Windows Server container, but you can specify that you want to run an Hyper-V container by using the flag --isolation=hyperv.

Here are some external links that could be useful to get more information about Windows Containers:

Have fun with Windows Containers & Docker !


Any question about this post? Feel free to drop a comment below or contact me on Twitter @jcorioland