Basic
Swarm is Docker’s in built containers orchestrator solution, its main purpose is to manage containers in a computer cluster, i.e. a set of connected computers that work together.
Swarm comes built into the Docker Engine, you don’t need to install anything to get started. |
In Docker, there are many layers of encapsulation: the OS kernel, containers, tasks that encapsulate containers as units of work, services or Pods that represent application components, and stacks(collection of services) that represent full applications.
docker swarm commands
docker swarm init |
Initialize a swarm |
docker swarm join --token<manager-token> 10.1.0.2:2377 |
Join an existing swarm as manager node |
docker swarm join --token<worker-token> 10.1.0.2:2377 |
Join a swarm as a worker node |
docker swarm leave |
Leave the swarm |
docker stack commands
docker stack deploy nodeapp -c docker-compose.yml |
deploy the stack using docker-compose file , Swarm does not support the build option if defined in the Compose file(but docker compose up uses it). |
docker stack ls |
shows all stacks along with list of services in the stack |
docker stack services <stack-name> |
list the services in the stack. |
docker stack ps <stack-name> |
list all the tasks in the stack. |
docker stack rm <stack-name> |
removes the stack. |
Manage Docker stacks( is a collection of services that make up an application in a specific environment).
docker service commands
docker service create --replicas 5 -p 80:80 --name web nginx |
create docker service directly (similar to docker run command) |
docker service logs [OPTIONS] SERVICE|TASK |
Fetch the logs of a service or task, in option you can use -f,--details etc |
docker service ls |
list all the services |
docker service ps [OPTIONS] SERVICE [SERVICE...] |
List the tasks of one or more services |
docker service rm SERVICE [SERVICE...] |
Remove one or more services |
docker service scale SERVICE=REPLICAS [SERVICE=REPLICAS...] |
Scale one or multiple replicated services |
docker service update [OPTIONS] SERVICE |
Update a service |
Manage services.Services in the swarm mode are actually object (when compared to the docker compose services where they are actual running services)
docker node commands
docker node ls |
List nodes in the swarm |
docker node ps |
List tasks running on one or more nodes, defaults to current node |
docker node rm [OPTIONS] NODE [NODE...] |
Remove one or more nodes from the swarm |
docker node demote NODE [NODE...] |
Demote one or more nodes from manager in the swarm |
docker node promote NODE [NODE...] |
Promote one or more nodes to manager in the swarm |
|
|
Common Terms/Key concepts
Node |
is a physical or virtual machine (running an instance of the Docker Engine.) |
Manager nodes |
perform swarm management and orchestration duties. By default manager nodes are also worker nodes. |
Worker nodes |
execute tasks. |
Cluster |
one or more nodes grouped together. |
Swarm |
is a type of cluster in docker terminology. |
Docker Swarm |
(not part of docker engine)is a separate product which you can use to cluster multiple Docker hosts. Prior to Docker version 1.12 it was the only native Docker option for clustering hosts, and it needed a lot of additional setup for distributed state, service discovery and security. |
Swarm Mode |
With Docker 1.12,(is built into Docker Engine) To run a cluster you just need to install Docker on multiple machines, run docker swarm init to switch to Swarm Mode and docker swarm join to add more nodes to the cluster. State, discovery and security are all included with zero setup. |
Stack |
is a collection of services that make up an application in a specific environment. |
service |
it defines the blueprint about which image to use and which commands to execute,ports,networks,replicas,etc inside future running containers. |
task |
in swarm model,task is actually invoked inside a container.When service is created the swarm manager starts a task(or its replicas) inside various containers. |
similar commands
Init host as a swarm manager node:
docker swarm init
Deploy application:
docker stack deploy -c docker-compose.yml myApp
List services:
docker service ls
docker stack services myApp
List tasks:
docker service ps myApp_web
docker container ls -q
docker stack ps myApp
Stop application:
docker stack rm myApp
Take down swarm
docker swarm leave --force
|
|
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by gauravpandey44