Docker Swarm

Getting Started

Requirement

  • Docker has been installed
  • The client and daemon API must both be at least 1.24 to use this command. (check docker version)

what is docker swarm?

Docker Swarm is a clustering and scheduling tool for Docker containers. With Swarm, IT administrators and developers can establish and manage a cluster of Docker nodes as a single virtual system.  

How Docker works?

Avoid single point of failure..

Docker Swarm Frequent USED Command

Docker Swarm Basic Command

Command  Description
docker swarm init Initialize a swarm.
 
docker swarm join Join a node to a swarm.
 
docker swarm join-token Manage join tokens
docker swarm leave Leave the swarm
docker swarm update Updates a swarm with new parameter values. 
docker swarm ca View or rotate the current swarm CA certificate.

Initialize a swarm. The docker engine targeted by this command becomes a manager in the newly created single-node swarm.

docker swarm init

Usage

docker swarm init --advertise-addr 192.168.65.3:3277

Join a node to a swarm.
The node joins as a manager node or worker node based upon the token you pass with the --token flag. If you pass a manager token, the node joins as a manager. If you pass a worker token, the node joins as a worker.

docker swarm join

Usage

#To Join As Worker
docker swarm join --token 
SWMTKN-1-0o98avmvaz953j5zcdi0cu2endu1efv0o7msg5rgg9029b80uh-7fxpvu7croo4a4q63sg50kw2p 
192.168.65.3:2377

#To Join As Manager
docker swarm join-token manager
docker swarm join --token 
SWMTKN-1-0o98avmvaz953j5zcdi0cu2endu1efv0o7msg5rgg9029b80uh-6ueth0rrghscogkbwwhu3c7cj 
192.168.65.3:2377

Manage join tokens

docker swarm join-token

Usage

docker swarm join-token (worker|manager)

When you run this command on a worker, that worker leaves the swarm.

You can use the --force option on a manager to remove it from the swarm.

However, this does not reconfigure the swarm to ensure that there are enough managers to maintain a quorum in the swarm.

The safe way to remove a manager from a swarm is to demote it to a worker and then direct it to leave the quorum without using --force. Only use --forcein situations where the swarm will no longer be used after the manager leaves, such as in a single-node swarm.

docker swarm leave

Usage

docker swarm leave

Updates a swarm with new parameter values. This command must target a manager node.

docker swarm update

Usage

docker swarm update --cert-expiry 720h

Manage Docker Swarm Nodes

Command  Description
docker node ls List nodes
 
docker node inspect (self/HOSTNAME) --pretty Inspect an individual node
 
docker node promote HOSTNAME Promote a worker node to the manager role.
docker node demote HOSTNAME Demote a manager node to the worker role.
docker node rm HOSTNAME Remove the node from the node list.

Manage Docker Swarm Services

Command Description
docker service create Create a new service
docker service inspect Display detailed information on one or more services
docker service logs Fetch the logs of a service or task
docker service ls List services
docker service ps List the tasks of one or more services
docker service rm Remove one or more services
docker service rollback Revert changes to a service’s configuration
docker service scale Scale one or multiple replicated services
docker service update Update a service

DEMO TIME

ci/cd

what is ci?

ci stands for continuous integration

It focuses on blending the work products of individual developers together into a repository

Primary purpose is to enable early detection of integration bugs

what is cd?

cd stands for continuous delivery

Focuses to minimize the friction points that are inherent in the deployment or release processes.

The implementation involves automating each of the steps for build deployments.

Text

Text

CI/CD Pipeline

Docker Swarm & CI/CD

By Syafiq bin abdul rahman