Getting started with Windows Containers: In Practice

In previous blog post, we discussed what are windows containers, how they are different from Hyper-V containers and how they are beneficial to developers and sysadmins. We also discussed how Docker as a company has played an important part in the story. In this blog post, we will get quickly get started with installing windows containers and run our first container image by pulling it from docker registry.

Environment Pre-Requisites

  1. You must have a machine with Windows Server 2016 or Windows 10 installed on it. It may be a physical machine or the virtual machine. On the Sku side, you can have either DataCenter version or Standard version as well. Or you may also use Windows Server Core version.
  2. If its a virtual machine, make sure it has nested virtualization enabled.
  3. All windows updates should be installed on the machine.
  4. Administrative access to the machine.

Install Windows Container Feature

We’ll get started by installing the Windows Containers feature on the container host by running below command:

Install-WindowsFeature -Name Containers

Install windows container feature
Install windows container feature

After this, we need to restart the computer. For this, we can use below command:

Restart-Computer

We can also check if windows feature for containers got installed properly by using below command:

Get-WindowsFeature -Name Containers

Verify if windows container feature is installed
Verify if windows container feature is installed

Install Docker Engine

Since container functionality is essentially provide by Docker, we need to install the Docker Engine. To achieve this goal, we have two options. The first one is to install it using PowerShell Module feature:

Install-Module -Name DockerMsftProvider -Repository PSGallery -Force
Install-Package -Name docker -ProviderName DockerMsftProvider

However, Microsoft has declared this as deprecated method. The new method is to install docker using the REST API interface provided by docker itself. This allows one to download the latest version, in order to get all new features.

This can simply be done by using below command:

Invoke-webrequest -UseBasicparsing -Outfile docker-17.06.2-ee-11.zip https://download.docker.com/components/engine/windows-server/17.06/docker-17.06.2-ee-11.zip

Download the Zip package containing docker binaries
Download the Zip package containing docker binaries

Now, we can extract the zip file using below command:

Expand-Archive docker-17.06.2-ee-11.zip -DestinationPath $Env:ProgramFiles

Now, we’ll add docker binary path to current session and also to the list of environment variables:

$env:path += “;$env:ProgramFiles\docker”

$newPath = “$env:ProgramFiles\docker;” + [Environment]::GetEnvironmentVariable(“PATH”,
[Environment]::SetEnvironmentVariable(“PATH”, $newPath,

Unpack archive and add docker binaries to environment variables
Unpack archive and add docker binaries to environment variables

Finally, we need to register the Docker daemon as a service by using below command:

dockerd –register-service

We also need to start docker service by using below command:

Start-Service Docker

Register and start the docker service
Register and start the docker service

Verifying Docker is Working

We can run docker info command to verify if we have installed it successfully. You should get an output like below:

Run docker info and check the output
Run docker info and check the output

We can also deploy our first Windows container! For the first example, we will deploy a hello-world container:

Running docker container from image hello-world
Running docker container from image hello-world

When you run the command, Docker checks if the image is available locally (on the container host). If not, then Docker retrieves the image from the Docker hub.

 

One thought on “Getting started with Windows Containers: In Practice

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s