Create a Docker Host on Microsoft Azure

This tutorial explains how to create a Docker Host on Microsoft Azure so that the standard Docker tools can be used to create and manage Docker containers on that host. If you are not sure what Docker is or why you might want a Docker Host you might want to read the Why Docker? page on the Docker website.

In order to make it as easy as possible to create a Docker Host we added a Docker feature to the cross-platform Azure Command Line Interface (CLI). In short this feature will create your Azure VM, install Docker on it and configure your client machine to with the necessary keys to access it securely.

Setting up your Work Environment

Docker does not currently run on Windows. If your work environment is running Windows, a few additional steps will be needed to create a Linux Virtual Machine to serve as a Docker client. We could create the Docker Host using the Azure CLI on Windows but then we would need to create a Linux client machine and configure it appropriately. For this reason we will use a Linux client machine.

NOTE: If you are already running Linux or OS X on your primary machine, then please skip ahead to the next section entitled “Install the Azure CLI”.

To create a Linux Virtual Machine on your Windows machine, you will need to:

  • Enable Hyper-V
  • Download Ubuntu 14.04 ISO
  • Create a Virtual Machine
  • Install Ubuntu on that Virtual Machine
  • Connect to the Virtual Machine

For those who need a more detailed information about this process, see Patrick Kennedy’s blog post on How to Run Ubuntu on Windows 8 Hyper-V.

Once the Linux virtual machine is running, you will do all further work in that VM rather than in Windows.

Install the Azure CLI

We will us the cross-platform Azure CLI (version 0.8.7 or greater) to manage our Docker host virtual machine. Once this host has been created, you will be able to use the standard Docker client tools to create and manage containers. For details on installing and using the Azure CLI, please reference Getting Started with Azure CLI Tools. Return to this section once you have completed this step.

Docker Client

In addition to the Azure CLI tools you will also need to install the Docker client tools. If you are following along and thus using Ubuntu, you should (see below for an explanation of why this is should, rather than can) be able to use the following commands:

apt-get install docker.io

Note the ".io" here. This is needed because there is another package called Docker.

However, at the time of this writing, the apt-get version is not the latest version. You will need version 1.0 or later. To check which version you have installed run:

docker --version

If you have a version pre 1.0 then you need to follow the instructions in the Docker documentation, HINT: for Ubuntu 14.04LTS simply run:

curl -sSL https://get.docker.io/ubuntu/ | sudo sh

Create a Virtual Machine for your Docker Host

In order to create a virtual machine that will act as our Docker host we will use the Azure CLI in almost the same way as we would if we were creating any other VM. The only significant difference is the addition of "docker" to the command. Therefore, the command takes the following format:

azure vm docker create -location "<location>" [options] <dns-name> <image> <user-name> [password]

This will create a VM and use the Azure VM Extension mechanism to install Docker. At the time of writing, a Linux VM is required to run Docker. In addition, the VM must also have an up-to-date version of the Azure Linux Agent (waagent). This means that our current options are either Ubuntu 14.04 from the gallery or a pre-rolled VM images that you create your Azure subscription. Additional images will made available in the future.For the purpose of this tutorial, we will use the Ubuntu 14.04 gallery image.

To find the ID of the Ubuntu 14.04 image, run the following command:

azure vm image list | grep 14_04

This will provide output something like this:Ubuntu Image List

While a number of images may be employed, we recommend using the most recent. In this case, we have selected the image published on 20140618 (the date string is in the image name).  Copy the image ID and use the “azure vm docker create” command to generate something like this:

azure vm docker create -e 22 -l 'West US' ubuntu-docker "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04-LTS-amd64-server-20140618.1-en-us-30GB" rgardler 1234abcdE$

The output of this command will then look something like this:

Docker Create Command Results

By following this process, the Ubuntu 14.04 virtual machine image will run the Docker daemon. This VM will act as a Docker host. It takes a few minutes for the VM to be fully provisioned and be ready to run commands to manage the host.

About Authentication

In addition to creating the Docker VM, this command also creates the necessary certificates to allow the Docker client to connect to the host using https. The first time you run an "azure vm docker create" command these certificates are generated automatically. They are stored on both the client and host machines, as appropriate. On subsequent runs, the existing certificates will be reused and shared with the new host.

By default, certificates are placed in ~/.docker, and Docker will be configured to run on port 4243. If you would like to use a different port or directory, then you may use one of the following command line options:

--docker-port [port]        Port to use for docker [4243]
--docker-cert-dir [dir]     Directory containing docker certs

The Docker daemon on the host is configured to listen for, and authenticate, client connections on the specified port using the certificates generated above. The client machine must have these certificates to gain access to the Docker host. Conversely, a networked host running without these certificates will be vulnerable to anyone that can to connect to the machine.

Creating Docker Containers

Now that you have a Docker Host available you can use standard Docker tools to create and manage containers on that host.


3 thoughts on “Create a Docker Host on Microsoft Azure

  1. Pingback: Deck and resources: Open Source + Microsoft Azure - KeithMayer.com - Site Home - TechNet Blogs

  2. Pingback: Exploring Azure Support for Docker | Alan Kent's Blog