August 25, 2022
This represents how the process I learned about Docker Swarm.
Container Orchestration automates most of the operational effort required to run workloads and services in containers. These operational efforts include deployment, management, scaling, networking, load balancing and more. Current software that provides this solution include Kubernetes, Docker Swarm, Hashicorp Nomad and others.
I have understood and used kubernetes to production usage, this blog post represents my own learning in trying Docker Swarm.
Simply put, we can easily manage 3 containers. However, imagine if there are tens to hundreds of containers, it will be easier to run in distributed mode in this case Container Orchestration. In addition, there will be many features that can be implemented to ensure they are running, healthy and more.
Let's deploy a scenario to put things in practice. This scenario consists of several simple HTTP services running on Docker Swarm, in this case on Google Cloud Platform (GCP).
We will try to expose a simple HTTP service so that it can be accessed by the internet. Docker host is used as a member of the unmanaged instance group and this instance group is the backend of the load balancer backend service.
In the instance group, 2 ports are addressed for each service. Load balancing will divide requests based on URL map routes to backend services.
Open up SSH sessions on each of the nodes.
Initialize the swarm on host manager:
manager:~$ sudo docker swarm init
# output
Swarm initialized: current node (yfswsafnaarbf1c29n1uknx5b) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
The output shows how to add a worker to the swarm using the token, IP and port (2377) to manage the cluster. If needed add a firewall to allow port 2377 on the node.
Copy and run the command on the worker host:
worker:~$ sudo docker swarm join --token token 10.184.0.4:2377
# output
This node joined a swarm as a worker.