{{tag>Docker HA}} # Docker Swarm Voir : * https://github.com/docker/swarmkit/ * https://devopssec.fr/article/comprendre-gerer-manipuler-un-cluster-docker-swarm ## Notes générales Vous allez avoir besoin d'au moins trois serveurs ou machines virtuelles avec Docker d'installé The network ports required for a Docker Swarm to function correctly are: TCP port 2376 for secure Docker client communication. This port is required for Docker Machine to work. Docker Machine is used to orchestrate Docker hosts. TCP port 2377. This port is used for communication between the nodes of a Docker Swarm or cluster. It only needs to be opened on manager nodes. TCP and UDP port 7946 for communication among nodes (container network discovery). UDP port 4789 for overlay network traffic (container ingress networking). ~~~bash ufw allow 22/tcp ufw allow 2376/tcp # Que sur le Manager ufw allow 2377/tcp ufw allow 7946/tcp ufw allow 7946/udp ufw allow 4789/udp ufw reload ufw enable systemctl restart docker ~~~ ~~~bash docker system info ~~~ and looking for a ''message Swarm: active'' Sur le Manager ~~~bash # docker swarm init --advertise-addr 192.168.99.121 docker swarm init ~~~ ~~~bash docker swarm join --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2 192.168.99.121:2377 ~~~ Voir l'état des nœuds ~~~bash docker node ls ~~~ https://www.grottedubarbu.fr/introduction-docker-swarm/ ~~~ $ openstack server create --image "Ubuntu 20.04" --flavor "s1-4" --key-name "MyKey" --net "Ext-Net" --user-data=docker.yaml my-manager $ openstack server create --image "Ubuntu 20.04" --flavor "s1-4" --key-name "MyKey" --net "Ext-Net" --user-data=docker.yaml my-worker1 $ openstack server create --image "Ubuntu 20.04" --flavor "s1-4" --key-name "MyKey" --net "Ext-Net" --user-data=docker.yaml my-worker2 ~~~ ''docker-compose.yaml'' ~~~yaml version: "3" services: viz: image: dockersamples/visualizer volumes: - "/var/run/docker.sock:/var/run/docker.sock" ports: - "8080:8080" ~~~ ~~~bash docker stack deploy -c docker-compose.yaml visualizer ~~~ Pour vérifier que votre service fonctionne : ~~~bash docker service ls ~~~ ~~~bash docker service ps --no-trunc visualizer docker service inspect visualizer ~~~ ## Registry Voir https://docs.docker.com/engine/swarm/stack-deploy/ ~~~bash docker service create --name registry --publish published=5000,target=5000 registry:2 ~~~ ~~~bash docker service ls curl http://localhost:5000/v2/ ~~~ Test the app with Compose ~~~bash docker-compose up ~~~ ~~~bash docker-compose down --volumes ~~~ Push the generated image to the registry ~~~bash docker-compose push ~~~ ## Déinstall ~~~bash docker service ls docker stack rm plop docker swarm leave --force ~~~ ## Autres ~~~bash docker swarm update --snapshot-interval 10000 systemctl restart docker ~~~