docker swarm init could not choose an IP address error

Justin picture Justin · Jul 27, 2016 · Viewed 25k times · Source

Experimenting with Docker Swarm with Docker Desktop for Mac. I tried this:

docker-machine create -d virtualbox node-1
docker-machine create -d virtualbox node-2
docker-machine create -d virtualbox node-3

eval $(docker-machine env node-1)

docker swarm init \
    --secret my-secret \
    --auto-accept worker \
    --listen-addr $(docker-machine ip node-1):2377

The last command (docker swarm init) returns this error:

Error response from daemon: could not choose an IP address to advertise since this system has multiple addresses

I have no idea what's going on. Anyone have any idea how to debug?

Answer

BMitch picture BMitch · Jul 27, 2016

Update 2017-05-24:

The prior answer was for an early state of swarm mode. The secret and auto-accept options have since been removed, and the advertise-addr option has been added. This can now by done with:

docker swarm init \
  --advertise-addr $(docker-machine ip node-1)

The port will default to 2377. You can also use a network interface name instead of an IP address and swarm will lookup the IP address on that interface. The listener address is still an option but the default is to listen on all interfaces which is typically the preferred solution.


Original answer:

I haven't done this with docker-machine yet, but I do know that the new swarm is very sensitive to the entries in /etc/hosts. Make sure your ip and hostname are in that file, and only in a single place (not also mapped to loopback or any other internal addresses). As of RC3, they are also using the listener address for the advertise address, too, so make sure this hostname or ip can be referenced by all nodes in the swarm (pretty sure a fix is coming for that, if not already here).

To minimize the risk of issues between client and server versions, I'd also run the commands directly inside the virtualbox, rather than with docker-machine environment variables.