docker swarm

Retour

create swarm (this host is now a manager)

docker swarm init

the command gives us the command to launch on the other hosts
we can also get this from this command :

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

now run the command to join the swarm on another host (this other host is now a worker)

docker swarm join --token xxxxxxxxxxxxx X.X.X.X:2377

remove tasks from a manager or reactivate it :

docker node update --availability drain
docker node update --availability active

show all hosts from manager

docker node ls

run this on every server to stop swarm :

docker swarm leave

remove a node from swarm from the manager

docker node rm fkvwjkdvyg4ymeeq0xak67j4w

configure swarm to automatically delete dead containers

docker swarm update --task-history-limit=1

deploy a stack

create a global network named public

docker network create --driver=overlay public

start or update a stack

docker stack deploy --with-registry-auth -c traefik.yml traefik
docker stack deploy --with-registry-auth -c swarmpit.yml swarmpit

stop

docker stack rm traefik
docker stack rm swarmpit

see swarm service (a stack creates services so you call it with stack_service).

# for a whole stack
docker stack ps errorpage
# for a specific service
docker service ps errorpage_errorpage
docker service inspect errorpage_errorpage
docker service logs -ft errorpage_errorpage