Home - About me - Browse by categories

Getting started with containers and Docker on Windows Server 2016 Technical Preview 5

The Technical Preview 5 of Windows Server 2016 has been released yesterday, and it comes with a lot of new cool things for Windows containers and Docker !

To get started with this new preview, you have two solutions:

I have chosen the second option, as it is simple and fast. Just search for Windows Server 2016 in the Azure MarketPlace and you’re done:

Marketplace

Once you are connected on your machine, you need to configure it to be a container host. It can be done with a few steps:

Install-WindowsFeature Containers

Once installed, you need to restart the machine using:

New-Item -Type Directory -Path 'C:\Program Files\docker\'
Invoke-WebRequest https://aka.ms/tp5/b/dockerd -OutFile $env:ProgramFiles\docker\dockerd.exe 
Invoke-WebRequest https://aka.ms/tp5/b/docker -OutFile $env:ProgramFiles\docker\docker.exe
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\Docker", [EnvironmentVariableTarget]::Machine)

The commands above create a new Docker folder in Program Files and download the docker deamon and client binaires in this directory. The last one adds the directory in the Path environment variable. The Docker deamon now supports an option to register it as a service on the machine:

dockerd --register-service

To start the docker service use:

Start-Service docker

Now, you need to download the base image for Docker containers on Windows. You can do it with the following commands:

Install-PackageProvider ContainerImage -Force
Install-ContainerImage -Name WindowsServerCore

Restart the Docker service:

Restart-Service docker

And your done!

docker info

Docker Windows

You can also get the list of available images on your system by typing:

docker images

Docker Windows

As you can see, an image named windowsservercore is available, but it does not have the “latest” tag. To tag it, type:

docker tag windowsservercore:10.0.14300.1000 windowsservercore:latest

Docker Windows

You can run your first container with the following command:

docker run -it windowsservercore cmd

It will run a new container in interactive mode and execute cmd inside the container:

Docker Windows

Type exit to leave the container.

As announced by Docker, it is now possible to write Dockerfile for Windows-based images and you can start to push/pull Windows images to and from the Docker Hub. Some example of Windows-based Dockerfile are available on GitHub: https://github.com/Microsoft/Virtualization-Documentation/tree/master/windows-container-samples/windowsservercore

For example, you can use this Dockerfile to create an image that will allow to run IIS in a container:

# This dockerfile utilizes components licensed by their respective owners/authors.
FROM windowsservercore
MAINTAINER [email protected]
LABEL Description="IIS" Vendor="Microsoft" Version="10"
RUN powershell -Command Add-WindowsFeature Web-Server
CMD [ "ping localhost -t" ]

Save this Dockerfile in an empty directory. Open a PowerShell window in this directory and build the container image with the docker build command:

docker build -t yourimagename .

Docker Windows

Once the image is built, login to your Docker Hub account using the docker login command:

Docker Windows

And push the image using the docker push command:

Docker Windows

Same experience than Docker with Linux containers ! It’s awesome !

Here are some resources that you may be interested in to go deeper in Windows Containers:


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