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 to how to provision docker hosts on azure using docker machine utility.
1. The system should be configured with azure CLI tools and the publishsetting file. I f you do not have CLI setup, follow this tutorial . How to set up Azure cli
2. You should have 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 installs 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
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
[email protected]:~/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" [email protected]:~/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.