Docker swarm cheat sheet

#Introduction

In this tutorial, I will study the Docker swarm cheat sheet. How to Management swarm and Handle nodes using CLI commands.

Here’s a Docker Swarm cheat sheet to help you with common commands and operations:

The Docker swarm cheat sheet

Docker swarm Management

Set up master

docker swarm init --advertise-addr <ip>
docker swarm init --advertise-addr

How to Force the Manager on a broken cluster

docker swarm init --force-new-cluster -advertise-addr <ip>

Enable auto-lock

docker swarm init –autolock

Get a token to join the workers

docker swarm join-token worker
docker swarm join-token worker

Get a token to join the new manager

docker swarm join-token manager
docker swarm join-token manager

Join the host as a worker

docker swarm join <server> worker

Have a node leave a swarm

docker swarm leave

Unlock a manager host after the docker

docker swarm unlock

Print key needed for ‘unlock’

docker swarm unlock-key

Print swarm node list

docker node ls
Docker swarm cheat sheet

Docker Service Management

Create a new service:

docker service create <options> <image> <command>

List the services running in a swarm

docker service ls

Inspect a service:

docker service inspect <service-id>

Scale a service (increase or decrease replicas)

docker service scale <service-id>=<replica-count>

Update a service:

docker service update <options> <service-id>

Remove a service:

docker service rm <service-id>

List the tasks of the service_name

docker service ps service_name

list running (active) tasks for a given service

docker service ps --filter desired-state=running <service id|name>

print console log of a service

docker service logs --follow <service id|name>

Promote a worker node to the manager

docker node promote node_name

The output terminal Promote a worker node to the manager as below

vagrant@controller:~$ docker node ls
ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
9b2211c8l1bmhu3h2ij3kthxv *   controller   Ready     Active         Leader           20.10.14
0j0pslqf4g6xkki8ajydvc123     node1        Ready     Active                          20.10.14
f4cxubqg0wqdxsaj8pe4qsqlg     node2        Ready     Active                          20.10.14

vagrant@controller:~$ docker node promote f4cxubqg0wqdxsaj8pe4qsqlg
Node f4cxubqg0wqdxsaj8pe4qsqlg promoted to a manager in the swarm.

vagrant@controller:~$ docker node ls
ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
9b2211c8l1bmhu3h2ij3kthxv *   controller   Ready     Active         Leader           20.10.14
0j0pslqf4g6xkki8ajydvc123     node1        Ready     Active                          20.10.14
f4cxubqg0wqdxsaj8pe4qsqlg     node2        Ready     Active         Reachable        20.10.14

Docker Stack Management

List running swarms

docker stack ls

Deploy a stack using a Compose file:

docker stack deploy --compose-file <compose-file> <stack-name>

Inspect a stack:

docker stack inspect <stack-name>

List services in a stack:

docker stack services <stack-name>

List containers in a stack:

docker stack ps <stack-name>

Remove a stack:

docker stack rm <stack-name>

Conclusion

You have noted the Docker swarm cheat sheet. This cheat sheet covers some of the essential commands used in Docker Swarm.

For a more detailed list of options and additional commands, you can refer to the official Docker documentation: https://docs.docker.com/engine/swarm/

I hope will this your helpful. Thank you for reading the DevopsRoles page!

,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.