# Docker Swarm
# What is Orchestration?
- To make it short, it means how we can manage our containers on multiple hosts.
- (2022) There are two popular Orchestration software.
- Kubernetes/Kube/K8s (opens new window)
- Docker Swarm Mode (opens new window)
- and more...
- K3s (opens new window) (Lightweight Kubernetes)
- openstack (opens new window) (supports VM cluster, Containe Orchestration or K8s)
# Main Feature Hightlights
- Cluster management
- Scaling
- Secure by default
- Rolling updates
# Understanding Workflow of Orchestration
- There is no build Docker Image concept in Orchestration.
- Therefore, we need Docker Registry for storing the Images because all node in cluster needs to pull from Docker Registry.
- There are many ways to store you Image(s).
- Docker Hub (opens new window)
- GitHub Container Registry (opens new window)
- Google Cloud Container Registry (GCR) (opens new window) (If you want to use K8s (Kubernetes), you might need GCP)
- create your own local Registry (opens new window) We will use this for workshop.
- and more ...
- There are many ways to store you Image(s).
- Orchestration will do their jobs (pull, run container(s), manage).
# Docker tag and how to push them link (opens new window)
{registry host}/{username}/{repositories or Image name}:{version}
1
# Docker hub
docker build . -t raknatee/my-image:v1
docker push raknatee/my-image:v1
1
2
2
# GCR
docker build . -t gcr.io/{PROJECT-ID}/my-image:v1
docker push gcr.io/{PROJECT-ID}/my-image:v1
1
2
2
# Local
docker build . -t localhost:5000/raknatee/my-image:v1
docker push localhost:5000/raknatee/my-image:v1
1
2
2
# Understanding Docker Swarm
# Node(s) link (opens new window)
- Node is a computer machine or VM.
- There are two types of node in Swarm.
- Manager node(s): used for cluster management, we can have multi-manager nodes but only one will be Leader of Manager node.
- Worker node(s): used for running container(s)
# Overlay Networks link (opens new window)
- To make it short, it looks like merge every IP address into one cluster. Therefore, you can access the cluster by using any IP address of hosts.
# Manager nodes for fault tolerance link (opens new window)
| Swarm Size | Majority | Fault Tolerance |
|---|---|---|
| 1 | 1 | 0 |
| 2 | 2 | 0 |
| 3 | 2 | 1 |
| 4 | 3 | 1 |
| 5 | 3 | 2 |
| 6 | 4 | 2 |
| 7 | 4 | 3 |
| 8 | 5 | 3 |
| 9 | 5 | 4 |
# Creates Swarm Cluster Nodes
In this example, we decided to create two nodes (VM) for Swarm Cluster.
- hostname: swarm-1 for MANAGER and being Leader
- hostname: swarm-2 for WORKER
WARNING
Please make sure that the following ports are available
TCP port 2377 for cluster management communications
TCP and UDP port 7946 for communication among nodes
UDP port 4789 for overlay network traffic
swarm-1
ssh swarm-1
1
docker swarm init --advertise-addr xxx.xxx.xxx.xxx
1
- xxx.xxx.xxx.xxx is IP address of swarm-1 machine.
output
Swarm initialized: current node (xxxxxxxxxxxxx) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token {token} xxx.xxx.xxx.xxx:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
1
2
3
4
5
6
7
2
3
4
5
6
7
swarm-2
ssh swarm-2
1
docker swarm join --token {token} xxx.xxx.xxx.xxx:2377
1