Creating a docker swarm cluster in Vagrant

1.1k views Asked by At

I'm trying to create a swarm cluster of diffferent ubuntu VMs running in Vagrant. These have docker enabled via the vagrant file that boots them. Of the three VM's I started the swarm cluster on one machine in the following way

docker pull swarm
docker run --rm swarm create

This returned a unique cluster_id. ON another docker enabled vm, I performed the following steps

  1. Stop the docker daemon

    sudo service docker stop

  2. Start the daemon with -H flag

    sudo docker -H tcp://0.0.0.0:2375 -d

This gives the following

    INFO[0000] +job init_networkdriver()
    INFO[0000] +job serveapi(tcp://0.0.0.0:2375)
    INFO[0000] Listening for HTTP on tcp (0.0.0.0:2375)
    INFO[0000] /!\ DON'T BIND ON ANY IP ADDRESS WITHOUT setting -tlsverify IF        YOU DON'T KNOW WHAT YOU'RE DOING /!\
    INFO[0000] -job init_networkdriver() = OK (0)
    INFO[0000] Loading containers: start.

    INFO[0000] Loading containers: done.
    INFO[0000] docker daemon: 1.6.2 7c8fca2; execdriver: native-graphdriver:aufs
    INFO[0000] +job acceptconnections()
    INFO[0000] -job acceptconnections() = OK (0)
    INFO[0000] Daemon has completed initialization

After this I start another session with this node and want to run run the following command:

sudo docker run -d swarm join --addr=<node_ip:2375> token://<cluster_id>

What is the node ip in this case? Using arp -an on this VM gives me three IP's which one is the one that is accessible

1

There are 1 answers

0
enrique-carbonell On BEST ANSWER

As show swarm/discovery in comment:

# on each of your nodes, start the swarm agent
#  <node_ip> doesn't have to be public (eg. 192.168.0.X),
#  as long as the swarm manager can access it.
$ swarm join --addr=<node_ip:2375> token://<cluster_id>

node_ip it's the ip address of the new node of the cluster.