docker swarm init could not choose an IP address error

29,398

Solution 1

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.

Solution 2

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)

Solution 3

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"

Solution 4

This works for me

docker swarm init --advertise-addr 127.0.0.1

enter image description here

Solution 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.

Share:
29,398

Related videos on Youtube

Justin
Author by

Justin

Updated on July 09, 2022

Comments

  • Justin
    Justin almost 2 years

    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?

  • Justin
    Justin almost 8 years
    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, docs.docker.com/engine/reference/commandline/swarm_init
  • BMitch
    BMitch almost 8 years
    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).
  • srivats
    srivats almost 8 years
    I think 1.12-rc4 does not have --advertise-addr flag. It is only available from 1.12-rc5.
  • Onur Tuna
    Onur Tuna almost 7 years
    It worked docker swarm init --advertise-addr X.X.X.X here you should give the ip of your host
  • vimal krishna
    vimal krishna over 6 years
    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
  • user27221
    user27221 almost 4 years
    instead of having to type your ip, you can do: docker swarm init --listen-addr `hostname -I | awk '{print $1}'`:2377 --advertise-addr `hostname -I | awk '{print $1}'`:2377
  • Admin
    Admin over 2 years
    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.