Skip to content
  • About Us
  • Our Services
  • Case Studies
  • Blog
  • Join Us
  • Contact Us
Getting Started With Docker on Windows
Ryan Lockard and Hibri Marzook

Getting Started With Docker on Windows

Docker for Windows Server is now in general availability. The latest announcement from the collaboration between Microsoft and Docker Inc, adds containerization to the toolkit for teams building with the Microsoft stack.

This new addition is what I call a "force multiplier", a capability that allows a team to accomplish greater things. Microsoft also released a Docker image for SQL Server Express last week, (https://hub.docker.com/r/microsoft/mssql-server-2014-express-windows/).

This removes a key pain point, in the development lifecycle for many teams. Testing becomes a lot more easier, with the ability to download a SQL server express image, test against it and throw it away. Expect to see a lot more of the tooling ecosystem that has been build around Docker to support Windows containers as well.

Windows Containers allows a server to act as container host for containers that can be managed with tools like Docker. However, a Windows container host can run only Windows containers, and not Linux containers.

I work on a Mac, and I want to use the Docker client on OSX to build Windows Containers. Here is what I went through to set up my environment to start playing with it.

Step 1

Build a virtual machine with the latest Windows 2016 Technical Preview (TP5 at the time of writing).

The usual way is to download, mount the iso in VirtualBox or VMware Fusion and install. After the installation, follow the quick start instructions to configure Windows Containers.

The quick start guide is at https://msdn.microsoft.com/en-us/virtualization/windowscontainers/quick_start/quick_start_configure_host

My preferred method is to create a Vagrant box, so that I can have a repeatable base build to experiment on.

Packer is the tool to build Vagrant boxes. There exists a Packer Windows project to build vagrant boxes. The main Packer Windows doesn’t contain templates for Windows Server 2016 yet. Stefan Scherer has been working on supporting it, and has built templates to provision container hosts as well. Clone the Packer templates from https://github.com/StefanScherer/packer-windows, and run

packer build windows_2016_docker.json

This tells packer to build a Vagrant box with Windows 2016 TP5 as a container host.

Once the box has been built, copy it to a place where it can be reused. My preferred place is a private Dropbox. You’ve now got a Vagrant box acting as a Windows Container Host, ready to experiment with.

Step 2

Spin up the Vagrant, Windows Container Host box by creating a Vagrant file

vagrant init -mf windows_2016_docker <url to your vagrant box>

Start the Vagrant machine by running

vagrant up

Wait till the Vagrant machine starts up.

Step 3

Connect the Docker client to the Vagrant machine running the Windows Container Host.

When the Vagrant machine starts up, it will display the IP address of the Vagrant machine. Use this IP address to set the DOCKER_HOST environment variable to tcp://:2375

In my environment it’s done by running,

export DOCKER_HOST=tcp://192.168.3.144:2375Then run <strong>docker version</strong> and look at the output. It should be something like the following.Client: Version: 1.11.1 API version: 1.23 Go version: go1.5.4 Git commit: 5604cbe Built: Wed Apr 27 00:34:20 2016 OS/Arch: darwin/amd64 Server: Version: 1.12.0-dev API version: 1.24 Go version: go1.5.3 Git commit: 2b97201 Built: Tue Apr 26 23:51:36 2016 <strong>OS/Arch: windows/amd64</strong>

The OS/Arch value should tell you that the Docker client on OSX, is connects to a Windows Host.

Step 4

Create a Dockerfile, with the following content.

FROM windowsservercore RUN powershell.exe Install-WindowsFeature web-server EXPOSE 80

This creates a Windows Docker Container image, using Windows Server Core as the base image, installs IIS, and exposes port 80

Build the Dockerfile.

docker build -t iis .

And run the image with

docker run --name iisdemo -d -p 80:80 iis

That’s it. You now have a container running IIS. Visit http:// to see the familiar IIS start page.

Summary

You’ve now got an environment to start experimenting with Windows Containers and Docker. You can start writing Docker files for your Windows only applications, and even start porting .Net services to run on Windows Containers.

More Articles

Get Up To Speed With Kubernetes And Java Spring Cloud

Get Up To Speed With Kubernetes And Java Spring Cloud

11 October 2016 by Jesse White
Terraform: Cloud Made Easy (Part 1 Of 4)

Terraform: Cloud Made Easy (Part 1 Of 4)

6 May 2016 by Jordan Taylor
Why Microservices Require a DevOps Approach

Why Microservices Require a DevOps Approach

15 January 2016 by Benjamin Wootton
  • Londonlondon@contino.io