Docker Swarm Cheat Sheet

Welcome to Our Docker Swarm Cheat Sheet!

overview
A swarm consists of multiple Docker hosts which run in swarm mode and act as managers (to manage membership and delegation) and workers (which run swarm services).
swarm commands
docker swarm initinitialises a new docker swarm
docker swarm join –tokenjoin a worker node to an existing swarm
docker swarm leaveleave the swarm
docker swarm init –autolockenables autolock on the swarm
stack commands
docker stack deployused to deploy a new stack
docker stack lslists all the stacks and services that make up the stacks
docker stack serviceslist the services in a given stack
docker stack pslist all the tasks for a given stack
docker stack rmremoves the stack
service commands
docker service create –replicas 5 -p 80:80 –name web nginxcreates a new docker service, based on nginx image with 5 replicas
docker service logsoutputs the logs of a service
docker service lslists all the services in the swarm
docker service rmdeletes a service
docker service scaleused to add or remove replicas from a service
docker service updateused to update a service with a new image
node commands
docker node lslists the docker nodes in a swarm
docker node pslists the tasks on a docker node
docker node rmremoves a node from the swarm
docker node demotedemotes a manager node
docker node promotepromotes a node to swarm manager
docker swarm network commands
docker network lslists networks
docker network create -d overlay network_name create overlay network
docker network rm network_name remove network
key concepts
NodeA physical or virtual machine on which docker is running
ManagerPerforms swarm management and orches­tration duties. Also acts as a worker node by default
WorkerRuns Docker Swarm tasks
Swarm ClusterA group of Docker nodes working together
StackA collection of services that typically make up an application
ServiceWhen you create a service, you define its optimal state (number of replicas, network and storage resources available to it, ports the service exposes to the outside world, and more).
TaskServices start tasks. A task is a running container which is part of a swarm service and managed by a swarm manager, as opposed to a standalone container.
swarm features
cluster managementfully integrated with the docker engine. No additional software required for docker swarm mode
decentralized designYou can deploy both kinds of nodes, managers and workers, using the Docker Engine. 
declarative service modelDocker Engine uses a declarative approach to let you define the desired state of the various services in your application stack.
scalingFor each service, you can declare the number of tasks you want to run.
desired stateThe swarm manager node constantly monitors the cluster state and reconciles any differences.
multi-host networkingYou can specify an overlay network for your services.
service discoverySwarm manager nodes assign each service in the swarm a unique DNS name
load balancingYou can expose the ports for services to an external load balancer.
rolling updatesIf anything goes wrong, you can roll back to a previous version of the service.
Useful Links
https://docs.docker.com/engine/swarm/
https://docs.docker.com/engine/swarm/how-swarm-mode-works/services/

Hopefully you have found this docker swarm cheat sheet to be useful. If so, please share using the social links below! Also, be sure to check out our other articles covering Docker Certification objectives!

Related posts

Docker Exec Command With Practical Examples

Debugging with Git Bisect

A Beginners Guide to Azure Repos

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More