DOCKER SWARM INIT
Usage: docker swarm init [OPTIONS] Initialize a swarm Options: --advertise-addr string Advertised address (format:[:port]) --autolock Enable manager autolocking (requiring an unlock key to start a stopped manager) --availability string Availability of the node ("active"|"pause"|"drain") (default "active") --cert-expiry duration Validity period for node certificates (ns|us|ms|s|m|h) (default 2160h0m0s) --data-path-addr string Address or interface to use for data path traffic (format: ) --dispatcher-heartbeat duration Dispatcher heartbeat period (ns|us|ms|s|m|h) (default 5s) --external-ca external-ca Specifications of one or more certificate signing endpoints --force-new-cluster Force create a new cluster from current state --listen-addr node-addr Listen address (format: [:port]) (default 0.0.0.0:2377) --max-snapshots uint Number of additional Raft snapshots to retain --snapshot-interval uint Number of log entries between Raft snapshots (default 10000) --task-history-limit int Task history retention limit (default 5)
Initialiser un swarm (Manager Status : -> Leader)
docker swarm init --advertise-addr ip-addr
L’option --advertise-addr spécifie l’interface réseau utilisée pour que le leader soit accessible par les autres nodes du swarm. Cette option est obligatoire s’il y a plusieurs interfaces réseaux sur le leader.
Une fois le swarm initialisé, le node à l’origine de l’initialisation est leader du swarm.
ex :
$ docker swarm init --advertise-addr 192.168.99.105 Swarm initialized: current node (2tbkss0ywais935a56ejcsaj3) is now a manager. To add a worker to this swarm, run the following command: docker swarm join --token SWMTKN-1-5gatiua1ou132p34xcd1ono2j88emxbwhy4uzvz1hodj0c1pi3-5bdfn48wm5hpiw5644rmnwhzk 192.168.99.105:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions. $ docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION 2tbkss0ywais935a56ejcsaj3 * node1 Ready Active Leader 18.06.1-ce
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
32841544151c bridge bridge local
32acdfbbac20 docker_gwbridge bridge local
6af2dc2c4d7c host host local
xpyxo8tirhe0 ingress overlay swarm
b6de6c7f9a85 none null local
Les réseaux bridge, host et none sont les réseaux par défaut, hors swarm, créés à l’installation du démon Docker.
Les réseaux ingress (connectivité depuis l’extérieur et routing mesh) et docker_gwbridge (connectivité vers l’extérieur) sont créés sur l’hôte à l’initialisation du cluster swarm.
Réinitialiser un swarm
docker swarm init --force-new-cluster --advertise-addr ip-addr
Force la création d’un nouveau cluster à partir de l’état courant.
Le contenu du dossier /var/lib/docker/swarm (dossier des logs et clefs du swarm) est maintenu en l’état, il n’est donc pas réinitialisé.
ex :
$ docker swarm init --force-new-cluster --advertise-addr 192.168.99.105