Search code examples
dockerapache-zookeeperdocker-swarm

Can not connect nodes to docker swarm master (using zookeeper)


I am building my docker swarm cluster in a sandbox. I have 1 zookeeper on a machine for discovery, 1 swarm master and 2 swarm nodes. I try to connect them but when I try to run my docker run commands on the swarm master, it does not distribute the work to the nodes. Also when I do docker info on the swarm master I can see that the nodes are not connected. I do not know what I am doing wrong. Here are the step to reproduce my problem:

I have an empty pwd/data folder and a pwd/config folder with my zoo.cfg:

tickTime=2000
dataDir=/tmp/zookeeper
clientPort=2181
initLimit=5

-

#---- CREATE ZOO ---

docker-machine create --driver virtualbox zoo1
docker-machine start zoo1
eval $(docker-machine env zoo1)

docker pull jplock/zookeeper

docker run -p 2181:2181 -v `pwd`/conf:/opt/zookeeper/conf -v `pwd`/data:/tmp/zookeeper jplock/zookeeper

docker-machine ip zoo1 #############192.168.99.100

-

#--- CREATE CLUSTER ---

docker-machine create --driver virtualbox --swarm --swarm-master machine-smaster
docker-machine create --driver virtualbox --swarm machine-s01
docker-machine create --driver virtualbox --swarm machine-s02

-

eval "$(docker-machine env machine-smaster)"
docker run -p 2375:2375 -d -t swarm manage -H 0.0.0.0:2375 --advertise $(docker-machine ip machine-smaster):2375 zk://192.168.99.100:2181/swarm
docker run swarm list zk://192.168.99.100:2181/swarm

sleep 10

eval "$(docker-machine env machine-s01)"
docker run -d swarm join --advertise $(docker-machine ip machine-s01):2375 zk://192.168.99.100:2181/swarm
docker run swarm list zk://192.168.99.100:2181/swarm

eval "$(docker-machine env machine-s02)"
docker run -d swarm join --advertise $(docker-machine ip machine-s02):2375 zk://192.168.99.100:2181/swarm
docker run swarm list zk://192.168.99.100:2181/swarm

If I run some containers:

eval "$(docker-machine env machine-smaster)"
docker run hello-world

The work is not dispatched to nodes (it is run by the master). If I run docker info:

eval "$(docker-machine env machine-smaster)"
docker info

I do not see the swarm nodes.


Solution

  • Can you verify that the addresses you're advertising are actually reachable from the manager instance? i.e., does docker -H $(docker-machine ip machine-s01):2375 info return a valid result?

    (Note that this subshell won't work inside the manager VM, just on your original client.)

    Maybe your problem is that the started Docker Machine instances are listening on :2376 with TLS, but your started Swarm containers are trying to advertise and connect to :2375 without any TLS settings specified?

    What do the docker logs for the Swarm containers say?