Deploying Micro-services using Docker Swarm – Part 1

Setup swarm

This tutorial might help you if you are deploying a stack of micro-service across a cluster of nodes using Docker Swarm mode. You can always achieve this goal using different platforms such as Kubernetes or Mesos, but it is almost always a more complicated process.

For the purpose of this tutorial we’ll deploy the following set of services in a cluster.

MicroserviceDescriptionSourceDocker image
Mainproxy servicesourcerabbie/dfn-poc:main-service
Autha mock auth servicesourcerabbie/dfn-poc:auth-service
Dataa mock data servicesourcerabbie/dfn-poc:data-service
Source: Darshana Samanpura


  • Working knowledge of docker and containers. If you are familiar with Docker but do not know what swarm is, I would recommend reading this documentation before proceeding.
  • A cluster of Linux nodes, interconnected through a network interface. For this tutorial, I will use a cluster of virtual machines in Google Cloud running Ubuntu 20.04 LTS.
  • Docker server and client pre-installed on all nodes.
  • At least one node should have access to the internet (Because our docker images are hosted in the cloud. This requirement can be skipped if we have a local container registry)

Overall solution

Basically what we are about to do can be broken down into 5 steps. 

  • Create a docker swarm
  • Define the swarm services
  • Create the swarm stack
  • Deploy the stack
  • Monitor and engage

Easy! right?

Step 1: Create the “swarm”

Every docker swarm cluster has nodes of 2 roles.

  1. Manager – we communicate with the cluster through this node
  2. Worker   – carries out tasks assigned by manager 

First we will create a manager and invite workers to join the cluster.

Step 1.1 : Create the Manager

SSH into one of your nodes and type this easy one-liner. (If you only have one node exposed to the public, this node should be it)

The response is self-explanatory. This very node has now become a manager and the token can be used to add nodes to this cluster. However, swarm allows having multiple managers per cluster as well.

Step 1.2 : Create a Worker

Now connect to each of the worker nodes and run the one-liner which was included in the response above.

Now we have successfully created a swarm of two nodes. In the next part of this tutorial, we will look into the concepts of a microservice in the docker swarm context.

Leave a comment

Your email address will not be published. Required fields are marked *