# Docker Swarm
# Node
print cluster nodes
docker node ls
1
get address + role
for node in $(docker node ls -q); do docker node inspect --format '{{.Status.Addr}} ({{.Spec.Role}})' $node; done
1
Print labels of nodes
docker node ls -q | xargs docker node inspect \
-f '[{{ .Description.Hostname }}]: {{ range $k, $v := .Spec.Labels }}{{ $k }}={{ $v }} {{end}}'
1
2
2
# Join new node
swarm manager shell
docker swarm join-token worker
1
We output a copy pastable bash line, like the following ! (Be carefull it doesn't include listen ip of the worker)
new worker shell
docker swarm join \
--token <TOKEN_WORKER> \
--listen-addr WORKER-LISTEN-IP:2377 \
<MANGER-LISTEN-IP>:2377
1
2
3
4
2
3
4
# Service
On swarm manager
# Print services for a given name
docker service ls --filter name=streaming --format '{{.Name}}'
docker service ls -f "desired-state=running" --format '{{.Name}}'
1
2
3
2
3
# Info of service
docker service ps api-streaming
1
# Filter on running services
docker service ps -f "desired-state=running" 869_api-games
1
# find where (NODE) an app is running.
docker service ps api-streaming --format '{{.Node}}'
node04
1
2
2
# Last time updated
docker service inspect log-master_logstash -f '{{ json .UpdatedAt }}'
1