Introduction to Docker Swarm(Part-1)

What is Docker Swarm?
Docker swarm is Container orchestration tool, meaning that it allows the user to manage multiple containers deployed across multiple host machines.
There are 2 main components of Docker Swarm:
- Swarm Manager
- Worker Node
Swarm Manager:- Swarm manager purpose is to receive commands on behalf of the cluster and assign containers to swarm nodes.
Worker Node:- is responsible for running container workload.
Steps to create Docker Swarm Cluster on Centos7:
- First setup your DNS server configuration if you haven’t already.
Make an entry of Hostname and IP address of manager node and nodes (minions) in the /etc/hosts file of both manager node and node.
192.168.0.33 managernode
192.168.0.32 workernode1
192.168.0.31 workernode2
2. Install Docker
- The following command to install Docker(1.19) on both nodes. Start and enable docker daemon.
yum install docker -y
NOTE: Docker Swarm comes bundled with Docker, so we just need to install Docker Package.
systemctl start docker && systemctl enable docker
- Verfiy the version of docker.
docker version
Client:
Version: 19.03.11
API version: 1.40
Go version: go1.14.3
Git commit: 42e35e6
Built: Sun Jun 7 21:16:58 2020
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 19.03.11
API version: 1.40 (minimum version 1.12)
Go version: go1.14.3
Git commit: 42e35e6
Built: Sun Jun 7 00:00:00 2020
OS/Arch: linux/amd64
Experimental: false
3. Launch the Swarm or Cluster
Initialized the swarm on your Manager node. To do this, run the command below:
docker swarm init — advertise-addr <swarm manager privateIP>
docker swarm init — advertise-addr 192.168.0.33
Swarm initialized: current node (q44lf9pqa8dheuf69hnin06b3) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join — token SWMTKN-1–48yuvbfmehbzksi0ss3a83119el1s0537pi0fucw4zvsfzs1eu-8l7pbpqkxsvziewhly23mvu2s 192.168.0.33:2377
To add a manager to this swarm, run ‘docker swarm join-token manager’ and follow the instructions.
3. Adding the Worker Node to the Cluster.
- Go to both worker node and execute this command.
docker swarm join — token SWMTKN-1–48yuvbfmehbzksi0ss3a83119el1s0537pi0fucw4zvsfzs1eu-8l7pbpqkxsvziewhly23mvu2s 192.168.0.33:2377
4. Go back to the swarm manager and list all the nodes
docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
q44lf9pqa8dheuf69hnin06b3 * node1 Ready Active Leader 19.03.11
trhn0vwmlf5w855y81fhzmzx3 node2 Ready Active 19.03.11
tp86b0238h6v9d9pxm4cow6n1 node3 Ready Active 19.03.11
5. In case, you want to retrieve a lost join token, run the command below:
docker swarm join-token worker
6. Verify the manager status using the command below:
docker info
Client:
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 19.03.11
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: active
NodeID: q44lf9pqa8dheuf69hnin06b3
Is Manager: true
ClusterID: drwny4uzynpki6vyjfkr9ufc3
Managers: 1
Nodes: 3
Default Address Pool: 10.0.0.0/8
SubnetSize: 24
Data Path Port: 4789
Orchestration:
Task History Retention Limit: 5
Raft:
Snapshot Interval: 10000
Number of Old Snapshots to Retain: 0
Heartbeat Tick: 1
Election Tick: 10
Dispatcher:
Heartbeat Period: 5 seconds
CA Configuration:
Expiry Duration: 3 months
Force Rotate: 0
Autolock Managers: false
Root Rotation In Progress: false
Node Address: 192.168.0.33
Manager Addresses:
192.168.0.33:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.4.0–186-generic
Operating System: Alpine Linux v3.12 (containerized)
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 31.4GiB
Name: node1
ID: M65I:GL7B:AWVN:74JM:46WK:CRBZ:DNHL:CGED:LUNO:R2XZ:G7LB:FXEF
Docker Root Dir: /var/lib/docker
Debug Mode: true
File Descriptors: 39
Goroutines: 174
System Time: 2020–09–15T07:39:31.291880836Z
EventsListeners: 0
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
127.0.0.1
127.0.0.0/8
Live Restore Enabled: false