25

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?

veben
  • 19,637
  • 14
  • 60
  • 80
Justin
  • 2,224
  • 2
  • 22
  • 28

7 Answers7

27

First look for the public IP of your machine on your network

ifconfig

pick the physical one like 192.168.1.x (not docker0, that is a virtual IP internal to Docker)

docker swarm init --advertise-addr 192.1.68.1.x

(will default to port 2377)

Genovo
  • 551
  • 6
  • 6
24

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.

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • I have no idea what happened, but the error now said: Error response from daemon: could not choose an IP address to advertise since this system has multiple addresses - specify one with --advertise-addr. So what I did was added the --advertise-addr to be the same as the --listen--addr flag, i.e., $(docker-machine ip node-1):2377. Then it worked. Don't know the difference between --listen-addr or --advertise-addr, and --advertise-addr does't seem to be in their documentation here, https://docs.docker.com/engine/reference/commandline/swarm_init/ – Justin Jul 27 '16 at 05:47
  • 3
    Nice to see advertise-addr made it into RC4. Configure the public ip or hostname with `--advertise-addr` and then just do a `--listen-addr 0.0.0.0:2377` (assuming that's your port). – BMitch Jul 27 '16 at 12:51
  • 3
    It worked `docker swarm init --advertise-addr X.X.X.X` here you should give the ip of your host – Onur Tuna May 24 '17 at 14:43
9

According to Docker´s guide: https://docs.docker.com/get-started/part4/#create-a-cluster

Getting an error about needing to use --advertise-addr?

Copy the IP address for your virtual machine by running docker-machine ls, then run the docker swarm init command again, using that IP and specifying port 2377 (the port for swarm joins) with --advertise-addr. For example:

docker-machine ssh myvm1 "docker swarm init --advertise-addr 192.168.99.100:2377"

  • 2
    this is exactly needed to start $ docker swarm init --advertise-addr 192.168.99.100:2377 Thanks! I have Docker version 17.05.0-ce-rc1, build 2878a85 – vimal krishna Oct 06 '17 at 20:30
6

This works for me

docker swarm init --advertise-addr 127.0.0.1

enter image description here

blazehub
  • 1,880
  • 19
  • 25
5

Got the same error when using docker with envs to connect to the docker-machine-created machine. After docker-machine ssh <machine-name>, and doing the docker swarm init locally on the machine, I got the message about --advertise-addr as well. The local command docker swarm init --listen-addr 192.168.99.100:2377 --advertise-addr 192.168.99.100:2377 then worked.

wscherphof
  • 61
  • 2
1

Check docker --version and make sure client and server are on the same version. If they are different, use the following command to pull the boot2docker version that matches with the docker client on your machine.

docker-machine create --driver virtualbox --virtualbox-boot2docker-url https://github.com/boot2docker/boot2docker/releases/download/v1.12.0-rc4/boot2docker-experimental.iso manager1

srivats
  • 11
  • 1
-1

Please ssh into the node 1 and then apply same command over there

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 16 '21 at 08:39