How to Provision Docker Hosts on Azure using Docker Machine

How to Provision Docker Hosts on Azure using Docker Machine

Docker machine helps you to spin up Docker hosts locally as well as with various cloud providers. This tutorial will teach you how to provision Docker hosts on Azure using the Docker Machine utility.

Prerequisites

1. The system should be configured with Azure CLI tools and the publishsettings file. I f you do not have CLI setup, follow this tutorial. How to set up Azure cli 2. You should have the latest docker-machine installed on your system.

Provision Docker Hosts on Azure

Provisioning Docker hosts on Azure is relatively easy. Docker machine will provision the VM and install the latest Docker engine on the VM based on its OS family. You can then deploy and manage containers from your laptop or host where Docker Machine is installed.

Creating a host using Docker Machine

Follow the instructions given below.

Execute the following command to create a docker host on azure using docker machine.

Note: Change id, YOUR-SUBSCRIPTION ID and USER-DEFINED-NAME accordingly. USER-DEFINED-NAME should be a unique name. If you try to use generic names, you will get an error saying that the name already exists.

docker-machine create -d azure --azure-subscription-id="YOUR-SUBSCRIPTION ID" --azure-subscription-cert="machine-cert.pem" USER-DEFINED-NAME

Example

By default, the docker machine azure driver creates an ubuntu 14.04 host.

docker-machine create -d azure --azure-subscription-id="52812b7b-7295-4e76-9c75-3b74b9abdc1f" --azure-publish-settings-file="credentials.publishsettings" --azure-location="East US" zeus-docker

To list all the environment variables set by docker machine for accessing the machine you have created, just execute the following command.

docker-machine env MACHINE-NAME

Output

mike@opsguy:~/keys$ docker-machine env zeus-docker
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://zeus-docker.cloudapp.net:2376"
export DOCKER_CERT_PATH="/home/mike/.docker/machine/machines/zeus-docker"
export DOCKER_MACHINE_NAME="zeus-docker"
mike@opsguy:~/keys$

Now, to run docker commands on your new machine, use the following command.

eval "$(docker-machine env zeus-docker)"

In your current terminal, you can run all docker commands against the Azure Docker host.

Moreover, you can create a swarm cluster on Azure using Docker Machine. We will cover that in the next article. Let us know in the comments section if you face any errors.

About the author
devopscube

devopscube

Since 2014, we're a thriving DevOps community dedicated to helping DevOps Engineers grow with high-quality, in-depth articles, comprehensive learning paths, expert insights, and practical resources.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to DevOpsCube – Easy DevOps, SRE Guides & Reviews.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.