Tech tutorials Intro to Azure Docker Swarm Mode — Part 1
By Insight Editor / 20 Jun 2017 , Updated on 16 May 2019 / Topics: Microsoft Azure Application development
By Insight Editor / 20 Jun 2017 , Updated on 16 May 2019 / Topics: Microsoft Azure Application development
I was asked to do some research on how to deploy a Java application in Azure. Although you could fire up and configure your own virtual machine or create a Tomcat App Service, the option that intrigued me the most was Docker for Azure. Based on my experiences, introducing Docker Swarm Mode first and then diving into Docker for Azure will make the most sense.
NOTE: If you’re completely new to Docker, read this article first.
Example diagram of a swarm cluster
Swarm mode is Docker’s container management and orchestration tool. This allows admins and software developers to create and manage multiple Docker containers running on one or more nodes. Because this is native to Docker, you can use the Docker API to run native tools such as Docker Compose. Theoretically, the software can handle up to 30,000 containers and clusters of up to 1,000 nodes without performance issues.
How services work
Node — a machine running the Docker engine. In most cases, this is a VM, but it can be a standalone server.
Service — the definition of the tasks to execute on the nodes. When creating a service, you specify what container image to use and any commands you wish to run on it.
Task — the Docker container and the commands to run inside the container. With swarm mode, you can have one or more tasks (e.g., multiple web server containers) to distribute the load of work being done.
Swarm — a cluster of Docker nodes. When initializing a swarm, you’ll create one or more “Manager” nodes and one or more “Slave” nodes. Managers are responsible for distributing tasks within the cluster based on what nodes are available, while workers receive and run tasks.
3. Create your VMs. We’ll be creating three VMs (one manager and two worker nodes).
Open a Windows command prompt and run as administrator. (This prevents Hyper-V precheck errors during your VM creation.) To create a VM using Hyper-V, run the following Docker machine command in the following format: > docker-machine create -d hyperv --hyperv-virtual-switch ""
For this example, I ran the following three commands:
> docker-machine create -d hyperv --hyperv-virtual-switch "PrimaryVirtualSwitch" manager1
> docker-machine create -d hyperv --hyperv-virtual-switch "PrimaryVirtualSwitch" worker1
> docker-machine create -d hyperv --hyperv-virtual-switch "PrimaryVirtualSwitch" worker2
4. Initialize your swarm.
Figure out the IP address allocated to each VM by running the following command:
> docker-machine ip <name-of-vm>
SSH into the manager node and initialize swarm mode on the manager by running the following:
> docker-machine ssh <name-of-manager-vm>
> docker swarm init --advertise-addr <manager-ip>
You should see output similar to the following if successful:
4. Now that the manager node is up and running, you can join your worker nodes to the manager. SSH into each worker node, just like you did into the manager, and then join them to the swarm by running the command generated from the docker swarm init command.
At this point, you should have three nodes created and talking to one another. Let’s start deploying some things and see how swarm mode works.
This concludes the basics on how to set up Docker swarm mode and how it works. In part 2, we’ll go over how we can do the same thing in Azure.