· Docker Getting Started

Create a Docker Host and application in Azure - the missing guide

You heard about Docker, you want to play around with it, but you have no idea where to get started. Here is the missing guide to get you quickly up and running.

Docker Architecture

A quick overview of what Dockers architecture is (taken from docs.docker.com):

Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers. Both the Docker client and the daemon can run on the same system, or you can connect a Docker client to a remote Docker daemon. The Docker client and daemon communicate via sockets or through a RESTful API.
Docker Architecture

We will use Azure for this exhibition. We have a few steps to do:

If you use Windows you need to install OpenSSL to create the certificates. Download and install it from slproweb.com. Here you’ll find Download Win32 OpenSSL.

  1. Install the neccessary tools
  2. Create a Docker host in Azure
  3. Connect to Docker Host with TLS security
  4. Start your first Docker Container
  5. Useful commands

1. Install the neccessary tools

Azure CLI

To create a Docker host in Azure we download the cross platform Azure command-line interface. This can be downloaded using npm install -g azure-cli. npm is the node package manager. To use npm you have to download NodeJs from nodejs.org.

Docker Client

To communicate with the Docker host you need the Docker Client.

2. Create a Docker host in Azure

For this we use the Azure CLI.

First identify yourself with Azure. You’ll get an aka.ms/devicelogin url with a token to do this using the web interface.

$ azure login

C:\> azure login

Now list all the available Ubuntu images, because this is the one we’ll use to initialize the Docker Host.

In Windows it’s useful to log the output of this command to a file and manually search in the file for Ubuntu-14_04, because the list is long and Windows has no grep.

$ azure vm image list | grep Ubuntu-14_04

C:\> azure vm image list > azureImagesList.txt

Now copy the image name you found in the last command and insert it inside the next command to create the Docker Host.

$ azure vm docker create -e 22 -l "East US" <vmname> "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04_3-LTS-amd64-server-20151218-en-us-30GB" <username> <password>

I’ll explain what this command does:

To get more information about this command, you can always run azure vm docker create --help.

3. Connect to Docker Host with TLS security

We’ve used the command azure vm DOCKER create. The docker part also installs the encryption and places the certificates in your personal directory on your current local machine. That is at ~/.docker/ or for Windows at %USERPROFILE%\\.docker. There are 3 files named <vmname>-server-cert.pem, <vmname>-key.pem and <vmname>-server.csr. You should backup these, in order to gain access to your Docker host using the Docker Client on another machine.

Using these certificates we will now connect to our Docker Host. The first thing is getting some info about the host.

$ docker --tls -H tcp://<vmname>.cloudapp.net:2376 info

I’ll explain what this command does:

To find more information about this you can always run docker --help.

4. Start your first Docker Container

Now that our connection succeeds, we can run our first Docker Container. For simplicity and high usability we’ll choose to create a DockerUI container. This is a containerized web application, to manage your Docker Host. You can find more info about this on github.com/crosbymichael/dockerui.


Please note that when we run this container and open the endpoint in Azure, everyone will have access to it and can manage your host. This image is not secured in any way.

To start this container run the following command.

$ docker --tls -H tcp://<vmname>.cloudapp.net:2376 run -d -p 9000:9000 --privileged -v /var/run/docker.sock:/var/run/docker.sock dockerui/dockerui bash

I’ll explain what this command does (without docker --tls -H <hostname> run):

This command actually runs two commands. Namely:

  1. docker pull dockerui/dockerui: this is because it cannot find the image dockerui/dockerui on your Docker Host, so it will download it from the Docker Hub
  2. docker run: this starts an image and creates a container from it

To make sure you can access this port from the interwebz, you need to add an endpoint to the Azure Virtual Machine and expose the port.

$ azure vm endpoint create -o tcp <vmname> 9000 9000

I’ll explain what this command does:

Now you’re done. When you go to http://<vmname>.cloudapp.net:9000 you’ll find the DockerUI website right in front of you.

5. Useful commands

In addition you could setup the following commands/tools.

View running and stopped containers

docker ps -a is there to show all running and stopped Docker containers.

$ docker ps -a
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                      NAMES
5d87edc5d68d        dockerui/dockerui       "/dockerui bash"         2 weeks ago         Up 8 hours>9000/tcp     dockerui

Start a stopped container

docker start name/id is there to start a stopped container.

$ docker start dockerui

Alias for docker client connection

If you dont want to use the full docker --tls -H tcp://<vmname>.cloudapp.net:2376-command, you can create an alias. You can store this line in ~./bash_profile and it’ll be persistent when you open your bash. Now you can run dockerazure info instead of the whole command including TLS and host

$ alias dockerazure="docker --tls -H tcp://<vmname>.cloudapp.net:2376"

For Windows you can use this command. You’ll have to enter this every time you open a new Command Prompt.

C:\> doskey dockerazure=docker --tls -H tcp://<vmname>.cloudapp.net:2376
  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket