I wanted to re-iterate an article I published on Azure Blog more informally, so here we are. In the past few months, I have been trying to make it damn easy to create Docker Swarm clusters on Microsoft Azure.
Whenever I have some distributed workload I want to deploy to cloud, I prefer Docker Swarm right away:
- it is easy to set up
- it is simple (it speaks the Docker CLI language)
Other orchestrators (as of writing) are more tedious to set up and configure and requires you to install additional things or write configuration files to run Docker containers. Swarm is nothing like that.
So if Swarm is really easy to use, why not make it really easy to create Docker Swarm clusters on Azure as well? And so my journey begins…
I came up with a way to let you create 3-master and 100-node Swarm cluster on Azure cloud in 5 minutes with only a few clicks.
All you need is:
- a Microsoft Azure account (free trial)
- a SSH public key file, a.k.a
Step 1: Go to GitHub and click “Deploy to Azure”, give us a public key and tell how many Swarm nodes do you want.
Step 2: Once deployment is completed, copy the SSH tunnel command. Run it in
a terminal window and keep it running, open another terminal window and run
docker commands against
localhost:2375 just as if Swarm is running on your
How it works?
When you click “Deploy to Azure” button from GitHub, the Azure Portal will ask for some inputs (SSH key and number of nodes). It uses Azure Resource Manager template to provision various resources (such as Virtual Machines, IP addresses, Load Balancers, NAT configurations, NICs, Availability sets).
The virtual machines are configured to run Docker using Azure Docker
Extension, which starts the docker-engine with a custom arguments and
Once it is all done, we provide you a SSH tunnel command that looks like:
$ ssh -L 2375:swarm-master-0:2375 -N [email protected] -p 2200
(…it will not print anything, but keep it running)
Then you can access the Swarm cluster just as if it is running locally:
$ export DOCKER_HOST=:2375
$ docker info
For the sake of fanciness of the new Azure portal, I deployed this through the web interface, but I could have used the Azure CLI as well.
You can find more information about this project on GitHub.
How do I cheat?
The end-to-end deployment of the Swarm cluster usually takes 5 minutes, no matter if you have 3 nodes or 100 nodes.
- I use CoreOS, which has docker pre-installed, so we do not wait for Docker installation.
- all virtual machines are deployed in parallel (Azure Resource Manager can handle provisioning of various resources in parallel).
- I don’t mess with Docker TLS certificates at all. Docker engines are behind a firewall and you can talk to Swarm Managers only through SSH tunneling (so it is SSH private key authentication). That said, any container can easily compromise the Docker engine. Therefore you need to make sure you are not running hostile or multi-tenant code in your cluster.
- I decide the VM username, IP addresses, domain names, storage account names etc. the cluster is going to use, but nobody should care really.
Can this get any easier? If you think so, please let me know.