⚠️ Traduction non officielle - Cette documentation est une traduction communautaire non officielle de Docker.

Ajouter des nœuds au swarm


Une fois que vous avez créé un swarm avec un nœud gestionnaire, vous êtes prêt à ajouter des nœuds travailleurs.

  1. Ouvrez un terminal et connectez-vous en ssh à la machine où vous voulez exécuter un nœud travailleur. Ce tutoriel utilise le nom worker1.

  2. Exécutez la commande produite par la sortie de docker swarm init de l'étape du tutoriel Créer un swarm pour créer un nœud travailleur joint au swarm existant :

    $ docker swarm join \
      --token  SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
      192.168.99.100:2377
    
    This node joined a swarm as a worker.
    

    Si vous n'avez pas la commande disponible, vous pouvez exécuter la commande suivante sur un nœud gestionnaire pour récupérer la commande de join pour un travailleur :

    $ docker swarm join-token worker
    
    To add a worker to this swarm, run the following command:
    
        docker swarm join \
        --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
        192.168.99.100:2377
    
  3. Ouvrez un terminal et connectez-vous en ssh à la machine où vous voulez exécuter un second nœud travailleur. Ce tutoriel utilise le nom worker2.

  4. Exécutez la commande produite par la sortie de docker swarm init de l'étape du tutoriel Créer un swarm pour créer un second nœud travailleur joint au swarm existant :

    $ docker swarm join \
      --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
      192.168.99.100:2377
    
    This node joined a swarm as a worker.
    
  5. Ouvrez un terminal et connectez-vous en ssh à la machine où le nœud gestionnaire s'exécute et exécutez la commande docker node ls pour voir les nœuds travailleurs :

    $ docker node ls
    ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
    03g1y59jwfg7cf99w4lt0f662    worker2   Ready   Active
    9j68exjopxe7wfl6yuxml7a7j    worker1   Ready   Active
    dxn1zf6l61qsb1josjja83ngz *  manager1  Ready   Active        Leader
    

    La colonne MANAGER identifie les nœuds gestionnaires dans le swarm. Le statut vide dans cette colonne pour worker1 et worker2 les identifie comme nœuds travailleurs.

    Les commandes de gestion Swarm comme docker node ls ne fonctionnent que sur les nœuds gestionnaires.

Et ensuite ?

Maintenant votre swarm consiste en un gestionnaire et deux nœuds travailleurs. Ensuite, vous allez déployer un service.