Search code examples
pythondockerdocker-swarm

docker swarm throwing an error "swarm already part of swarm"


docker swarm throwing an error "swarm already part of swarm" when I am joining the new node to the existing node

I am running the docker swarm in my local machine and trying to init the swarm and getting executed very well but when i am trying to add the new worker or node to the existing manager node then it is throwing an error like swarm already part of the node you have to leave the node. $docker swarm init Swarm initialized: current node (fn405d6jtk8mxbpvdrftr0np1) is now a manager.

To add a worker to this swarm, run the following command:

docker swarm join --token SWMTKN-1-5tyw8ux789wpa7yyt75qbilb669tiw53pxriyxu48niznpmaka-7u63l4hom3h60myvtyw8p1mcj 192.168.2.219:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

=>And again am using above token as a worker and join then i gotta error like this..

$    docker swarm join --token SWMTKN-1-5tyw8ux789wpa7yyt75qbilb669tiw53pxriyxu48niznpmaka-7u63l4hom3h60myvtyw8p1mcj 192.168.2.219:2377

Error response from daemon: This node is already part of a swarm. Use "docker swarm leave" to leave this swarm and join another one.

Solution

  • The Docker swarm is a collection of one or more machines (physical or virtual, called nodes) that can run your containers as services. Nodes in the swarm can be managers or workers. Only on manager nodes can you see/modify the swarm status. Worker nodes only run containers. In order to run a container in the swarm you must create a service; that service will have zero or more containers depending on the scale that you set for the service.

    To create a swarm, you run the docker swarm init on the machine that will be a manager node. Then, on the other machines that you own you run the docker swarm join command in order to add them to the swarm. You cannot add to the swarm a machine that already is on the swarm. In your case, you try to add to the swarm the manager that created the swarm.

    When you initiate a swarm (with docker swarm init), the machine from that you initiated the swarm is already connected to the swarm, you don't need to do anything else to connect it to the swarm.

    After you initiate the swarm, you may (and should) add other machines as managers or workers.

    At any point after you have created the swarm, you can create services and/or networks or deploy stacks.