Creating an Azure VM with Docker

The Docker web site (https://www.docker.com/) provides a very good overview of the Docker architecture and how it works, in case you want to gain a deeper understanding of Docker internals. For the purpose of this book, we do not need to understand all the details of Docker, so let’s have a look at the parts that are relevant for us.

If we want to run Docker containers, we need a Docker host machine. The piece that is really needed on the host machine is the Docker daemon. This is responsible for managing Docker images and containers on the host. To communicate with the Docker daemon, we use the Docker client. The Docker client is really just a binary that talks to the Docker Remote API implemented in the Docker daemon. The Docker client can be used remotely, but can also be installed on the Docker host alongside the Docker daemon.

The fundamental features when working with Docker are images, containers, repositories and volumes. The best way to explore those features is to work with them. Over the next few pages, we will discuss how to set up a VM in Azure as a Docker host machine, and explore fundamental Docker commands.

There are several ways to install Docker on an Azure VM:

Command Line Interface: The Azure CLI tools on Windows and Mac OS X enable us to create virtual machines that include Docker.

The command “azure vm docker create -location "<location>" [options] <dns-name> <image> <user-name> [password]” creates an Azure VM and uses the Docker extension to install Docker. At the time of writing there is no command line option for an SSH public key; you have to use a username and password instead.

Another CLI option is to use Docker Machine. Docker Machine is part of the Docker toolbox and simplifies the creation of Docker hosts on your computer, on cloud providers, and inside your own data center.

The command

docker-machine_linux-amd64 create -d azure
      --azure-subscription-
id="<subscriptionID>"
      --azure-subscription-cert="mycert.pem"
  machine-name

creates a Docker host on Azure.

Azure Resource Manager (ARM) templates: Azure Resource Manager enables you to declaratively describe your environment in a template, and deploy and manage it as a single unit. In Chapter 5, we will have a closer look at Azure Resource Manager. There are many templates for Docker. including quickstart templates available on GitHub (https://github.com/Azure/azure-quickstart-templates) that enable users to provision an environment directly into Azure.

PowerShell: PowerShell can be used to deploy Azure Resource Manager templates.

The command “New-AzureResourceGroupDeployment -Name $Name -ResourceGroupName $RGName -TemplateUri $vmTemplateURI --TemplateParameterObject $parameters -Verbose” will provision a new Azure environment based on the template that has been submitted.

Azure Portal: Provides a UI for creating Azure VMs, including one with Docker installed.

There is no Azure VM image that has the Docker daemon preinstalled; in all cases Docker is installed as a VM extension to the Azure VM.


Image VM Extension

A virtual machine extension is a software component enabling in-guest management customization tasks such as adding software or enabling debugging and diagnostics scenarios. Extensions are authored by Microsoft and trusted third parties like Puppet Labs and Chef. The set of available extensions is growing all the time. The Docker extension installs the Docker daemon on supported Linux-based virtual machines. Extension can be installed in through the portal, command line tools (such as Azure CLI), PowerShell, or Visual Studio.


In this chapter we use the easiest way possible: we provision an Azure VM from an image that will install Docker as part of the virtual machine provisioning process through the Azure Portal.


Image Install Docker on a Development Machine

To install Docker locally on a machine (Mac OS, Linux, or Windows) we should use Docker Toolbox. Toolbox is a collection of Docker tools bundled in a single installer. For more information go to this URL: https://www.docker.com/toolbox. For a graphical user interface we can install Kitematic from Docker (for Windows and Mac). Chapter 4, “Setting Up Your Development Environment,” covers setting up Docker locally in more detail.


Before we create the Azure VM we need to generate an SSH key that we will use to connect to the Azure VM.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.173.199