Cannot swarm init: cannot assign requested address

Expected behavior

$ docker swarm init --listen-addr 192.168.2.28:2377
Swarm initialized …

Actual behavior

$ docker swarm init --listen-addr 192.168.2.28:2377
Error response from daemon: listen tcp 192.168.2.28:2377: bind: cannot assign requested address

Information

Attempting to follow the swarm tutorial.

Diagnostic ID: 4DA8D1D8-B659-4C77-B6E0-7CF74540D35F

Docker for Mac: version: mac-v1.12.0-beta16.2
OS X: version 10.10.5 (build: 14F1808)
logs: /tmp/20160624-162929.tar.gz
failure: No error was detected
[OK] docker-cli
[OK] app
[OK] menubar
[OK] virtualization
[OK] system
[OK] osxfs
[OK] db
[OK] slirp
[OK] moby-console
[OK] logs
[OK] vmnetd
[OK] env
[OK] moby
[OK] driver.amd64-linux

Port 2377 is available. The 192.168.2.28 address is my local ethernet card address.
en3: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV>
ether 38:c9:86:2f:f8:8f
inet6 fe80::3ac9:86ff:fe2f:f88f%en3 prefixlen 64 scopeid 0x9
inet 192.168.2.28 netmask 0xffffff00 broadcast 192.168.2.255
nd6 options=1
media: autoselect (1000baseT <full-duplex,flow-control,energy-efficient-ethernet>)
status: active

Steps to reproduce the behavior

As above, simply run the command.

I also tried this on another of my Mac machines, with the same result.

Does your use-case actually require a custom listen address? docker swarm init should work just fine.

The native Docker for Mac is not actually a native app that runs on your host’s kernel, to know about your network.

The Docker engine is running in an Alpine Linux distribution on top of an xhyve Virtual Machine on Mac OS X or on a Hyper-V VM on Windows, and that VM is managed by the Docker application.

You basically provide docker with a host interface which from its perspective doesn’t exist.

The docker command runs natively on the mac, it should be able to see the network. The docker command may start things inside a container, but the docker command itself is not in a container, so it should be able to see my network and do the needful things. This is one of the things the new docker for mac should solve, should it not?

The docker command runs natively on the mac

This is a very true statement.

What you run on your Mac is actually just a docker client command, which, indeed, is native.

On the other hand the actual Docker Engine daemon, which receives commands from the docker client, runs on linux kernel inside a VM on Mac. See the quote from my previous message. That’s actually taken out of the release message.

Just run docker info on your Mac and see the “Operating System” section.

Here’s a good example that you can try yourself:

  • Run ifconfig on you Mac
  • Run ubuntu container with --net=host, which would expose the host’s networking stack inside a container
  • Run ifconfig inside container

What you’ll see is two different sets of interfaces.

There is no such thing as native Docker Engine. Docker Engine only runs on linux kernel. So, unless you are on Linux host, you will have this issue.

1 Like

I’m having this same basic issue. My iMac has the IP address 192.168.1.11 and if I …

docker swarm init --listen-addr 192.168.1.11:2377
No --secret provided. Generated random secret:
1c79m0rzsar2ng8gcuf8wz97d

Error response from daemon: listen tcp 192.168.1.11:2377: bind: cannot assign requested address

One of the responses above suggests running init without listen-addr which gives …

docker swarm init
No --secret provided. Generated random secret:
eufek6klwo61assrbsht8d8rw

Swarm initialized: current node (76hub80cls66ad1piyqj2quin) is now a manager.

To add a worker to this swarm, run the following command:
docker swarm join --secret eufek6klwo61assrbsht8d8rw
–ca-hash sha256:0d20ace10223db92413d8199b36d488475b7bf9ca0d60303433c4272bb6b055d
192.168.65.2:2377

The problem is that it is using the IP address 192.168.65.2 which is not reachable from another machine (my laptop).

I am also facing the same issue. When I try to use my mac ip address as listen address. I am getting error ‘bind: cannot assign requested address’

My Docker version :
Version: 17.06.0-ce
API version: 1.30 (minimum version 1.12)
Go version: go1.8.3
Git commit: 02c1d87
Built: Fri Jun 23 21:51:55 2017
OS/Arch: linux/amd64
Experimental: true

1 Like

I got it working using socat containers to forward swarm ports from VM network to host
posted example compose file here Error response from daemon: listen tcp: bind: cannot assign requested address · Issue #1146 · moby/swarmkit · GitHub

I am facing the same issue, my IP address is 192.168.0.223 and If I run the ‘docker swarm init’ then it provide me the ip address that is not the same to the machine ip, and when I used the command ‘docker swarm init --listen-addr 192.168.0.223:2377 --advertise-addr 192.168.0.223:2377’ it said: can’t assign the requested address

please Explain, if you have the solution

Of couse it will not work like this with Docker Desktop, as it always runs the docker engine in a vm and therefor the host ip does not apply in this scenario.
You can not assign an ip as listen address that does not exist in the vm.

I suggest to leave --listen-addr alone (which defaults to 0.0.0.0:2377) and probalby set --advertise-addr to your host ip:2377 instead. I have no Idea if Docker Desktop actually forwards that port from your host to the vm, but if it’s working, then this should be the way.

Seems I was wrong regarding --advertise-addr, as it only seem to specify which ip to use if multiple ips exist. I am afraid this one also needs to be known to the vm and as such stil can’t be the host ip:

1 Like

Thanks for your reply. It works only if I provide the docker desktop ip address which is 172.17.0.1 in listen-addr and my machine ip to advertise-add but it doesn’t route the traffic.

I was wrong regarding --advertise-addr: unlike --listen-addr, it does not need to exist inside the utility vm and should use the {host-ip:2377}.

The --listen-addr should remain the default value.

Setup like docker swarm init --advertise-addr {DD host ip}:2377, the swarm endpoint should accept connections on all(!) interfaces of the utility vm, and advertise the host’s ip to be used for swarm communication.

Next thing that needs to be established is: does the host os bind the vm port 2377/tcp + 7946/udp + 7946/udp + 4789/udp? It woll not work without those ports beeing forwarded from the host to utility vm.
As I only have access to Docker Desktop for Windows, I can only say that from a first look it doesn’t appear like these ports are actually forwarded from the host to the utility vm.

There is a socat docker image for forwarding host ports to the services inside the virtual machine.
https://hub.docker.com/r/alpine/socat

Quote:

Use Case: Expose a tcp socket for accessing docker API on macOS

The Docker for Mac native macOS application provides use of docker engine without the need for vagrant or other virtualized linux operating system. Docker for Mac does not provide the same docker daemon configuration options as other versions of docker-engine. macOS-socat uses socat to establish a tcp socket bound to localhost which makes available the Docker for Mac API.

It is about the Docker API, but you can also use it for Docker Swarm. I remember a similar question from the past which I can’t link now, but I played with Docker Swarm on macOS then.

As far as I know Docker Desktop forwards ports only that you explicitly forwarded with the -p option of docker run or the equivalent Docker Compose parameters in the YAML file.

Docker works because the unix socket is forwarded into the VM and the Kubernetes API server port works, but you can enable Kubernetes from the Docker Desktop UI. There is no option to enable Docker Swarm. It could be a good feature requirest if you think it would be useful.

1 Like