I’ve written about using Docker Machine with a number of different providers, such as with AWS, with OpenStack, and even with a local KVM/Libvirt daemon. In this post, I’ll expand that series to show using Docker Machine with Azure. (This is a follow-up to my earlier post on experimenting with Azure.)
As with most of the other Docker Machine providers, using Docker Machine with Azure is reasonably straightforward. Run
docker-machine create -d azure --help to get an idea of some of the parameters you can use when creating VMs on Azure using Docker Machine. A full list of the various parameters and options for the Azure drive is also available.
The only required parameter is
--azure-subscription-id, which specifies your Azure subscription ID. If you don’t know this, or want to obtain it programmatically, you can use this Azure CLI command:
az account show --query "id" -o tsv
If you have more than one subscription, you’ll probably need to modify this command to filter it down to the specific subscription you want to use.
Additional parameters that you can supply include (but aren’t limited to):
- Use the
--azure-imageparameter to specify the VM image you’d like to use. By default, the Azure driver uses Ubuntu 16.04.
- By default, the Azure driver launches a Standard_A2 VM. If you’d like to use a different size, just supply the
--azure-locationparameter lets you specify an Azure region other than the default, which is “westus”.
- You can specify a non-default resource group (the default value is “docker-machine”) by using the
- The Azure driver defaults to a username of “docker-user”; use the
--azure-ssh-userto specify a different name.
- You can customize networking configurations using the
--azure-vnetoptions. Default values for these options are 192.168.0.0/16, “docker-machine”, and “docker-machine”, respectively.
So what would a complete command look like? Using Bash command substitution to supply the Azure subscription ID, a sample command might look like this:
docker-machine create -d azure \
--azure-subscription-id $(az account show --query "id" -o tsv) \
--azure-location westus2 \
--azure-ssh-user ubuntu \
--azure-size "Standard_B1ms" \
This would create an Azure VM named “dm-azure-test”, based on the (default) Ubuntu 16.04 LTS image, in the “westus2” Azure region and using a username of “ubuntu”. Once the VM is running and responding across the network, Docker Machine will provision and configure Docker Engine on the VM.
Once the VM is up, all the same
docker-machine commands are available:
docker-machine lswill list all configured machines (systems managed via Docker Machine); this is across all supported Docker Machine providers
docker-machine ssh <name>to establish an SSH connection to the VM
eval $(docker-machine env <name>)to establish a Docker configuration pointing to the remote VM (this would allow you to use a local Docker client to communicate with the remote Docker Engine instance)
docker-machine stop <name>stops the VM (which can be restarted using
docker-machine start <name>, naturally)
docker-machine rm <name>deletes the VM
Clearly, there’s more available, but this should be enough to get most folks rolling.
If I’ve missed something (or gotten it incorrect), please hit me up on Twitter. I’ll happily make corrections where applicable.
Lowe, S. (2018). [online] Available at: https://blog.scottlowe.org/2018/01/25/using-docker-machine-with-azure/ [Accessed 16 Feb. 2018].