Monday, 4 January 2016

Microscaling in Native Windows Containers - Part 1

Native Containers on Windows 2016

Until very recently you only had one OS option for running Docker containers -  Linux. You couldn't run containers natively on Mac or Windows.

Docker do a great job of allowing you to develop and test Linux Docker containers on Windows or Mac inside the Boot2Docker VM, but the Docker client and daemon are still running on a Linux OS within your Boot2Docker VM.

Now there's another option (at least in preview) - the Docker client and daemon will run natively on Windows 2016 Server and you can run Windows Docker containers there.

This post takes you through a worked example of how to port an application to run in a native Windows Container. I'll use our application, Force12, as our example.

Part 1 covers how to set up an Azure Windows 2016 host VM to try out Windows Containers.

Windows Docker Containers?

First off, let's be clear that Windows 2016 only runs Windows Docker containers natively. You can't run your existing Linux Docker containers natively on Windows and you'll never be able to. Let it go.

This article is about creating new Windows containers with Windows-compatible content and running them on Windows.

PowerShell Containers Vs Docker Containers

To confuse things further, Windows 2016 supports both Docker containers and PowerShell containers. These are not interchangeable either. If you create a container using Docker you have to manage it using Docker. If you create a container using the new PowerShell container commands you have to manage it using PowerShell commands.

This article is about creating, running and managing Docker containers on Windows.

We can worry about PowerShell containers another time.

Aside - How does this all work?

Just for background info, Microsoft formed a team of developers to work with Docker on stuff including adding a shim into the Docker daemon to create/start etc.. containers on Windows. The shim is open source and you can see it in the Docker repo on github. The shim is written in Go and sits on top of the WinAPIs, using familiar WinAPI calls like LoadLibrary to drive the WinOS container functionality in a Docker-like way. 

Getting Started

In part 1, we start with simply creating a Windows 2016 machine to play with.

To get started the first thing we'll need is a Windows 2016 Server with the Windows Docker daemon installed. You can set up your own server, but the easiest way to do this is by creating a VM on Azure. (Azure has a free 1 month trial plan so this doesn't need to cost anything).

Step 1 - Set up an Azure account

Visit and follow the instructions

Step 2 - Set up a Windows 2016 Server Host VM  

To create a test VM

  • Log into the Azure portal using your account
  • Select "Virtual Machines" in the left hand navigation
  • Click the + Add button to create a new VM

  • Type "containers" in the search box
  • Select "Windows Server 2016 Core with Containers Tech Preview 4" from the returned options

Select the image, and click Create for the first of many times ;-)

Give the Virtual Machine a name, select a user name and a password

  • Select Optional Configuration > Endpoints > 
  • enter an HTTP endpoint with a private and public port of 80. Now click OK in both tiles

Click the create button to kick everything off

When the VM is ready and started, click on the running VM in "Virtual machines (classic)" , then click the Connect button to start an RDP session with the VM
You can log into the VM using the username and password you provided during creation. Once logged in you will be looking at a Windows command prompt. Yay!
You can type "start cmd.exe" into that command prompt to get another prompt, which will be handy later.

At this point brace yourself. This Windows 2016 Server variant DOES NOT COME WITH A GUI. This really is preview stuff. You're going to have to use the command prompt and PowerShell to start with. Don't panic ;-) We'll step through it in Part 2.

No comments:

Post a Comment