# Docker Swarm

# What is Orchestration?

# Main Feature Hightlights

  • Cluster management
  • Scaling
  • Secure by default
  • Rolling updates

ref (opens new window)

# Understanding Workflow of Orchestration

  1. There is no build Docker Image concept in Orchestration.
  2. Therefore, we need Docker Registry for storing the Images because all node in cluster needs to pull from Docker Registry.
  3. Orchestration will do their jobs (pull, run container(s), manage).
{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

# GCR

docker build . -t gcr.io/{PROJECT-ID}/my-image:v1
docker push gcr.io/{PROJECT-ID}/my-image:v1
1
2

# Local

docker build . -t localhost:5000/raknatee/my-image:v1
docker push localhost:5000/raknatee/my-image:v1
1
2

# Understanding Docker Swarm

  • 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)
  • 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.
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

swarm-2

ssh swarm-2
1
docker swarm join --token {token} xxx.xxx.xxx.xxx:2377
1

# Workshop

# Counter