docker swarm container bind address other than 0.0.0.0
I got a multi-node docker swarm setup with the following interfaces:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:8d:c0:4d brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0
valid_lft 47333sec preferred_lft 47333sec
inet6 fe80::a00:27ff:fe8d:c04d/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:fe:3f:4d brd ff:ff:ff:ff:ff:ff
inet 10.0.1.2/24 brd 10.0.1.255 scope global eth1
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fefe:3f4d/64 scope link
valid_lft forever preferred_lft forever
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:94:ee:64:8f brd ff:ff:ff:ff:ff:ff
inet 10.0.1.2/24 brd 10.0.1.255 scope global docker0
valid_lft forever preferred_lft forever
9: docker_gwbridge: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:12:4b:f2:fa brd ff:ff:ff:ff:ff:ff
inet 172.18.0.1/16 brd 172.18.255.255 scope global docker_gwbridge
valid_lft forever preferred_lft forever
inet6 fe80::42:12ff:fe4b:f2fa/64 scope link
valid_lft forever preferred_lft forever
When starting the most simple container stack docker swarm deploy -c simple.yml simple
version: "3.7"
services:
whoami:
image: traefik/whoami
ports:
- 80:80
The container get placed and the service gets bound to 0.0.0.0
. Not exactly ideal.
Better would be for the container to bind to the eth1=10.0.1.2/24
interface. Ideally also lo
- but that would be just the icing on the cake.
What I've tried is to start the docker instances with their respective IPs from the network.
--ip ip Default IP when binding container ports (default 0.0.0.0)
So based on the docs for example: dockerd --ip 10.0.1.2
. Unfortunately that does not seem to change a thing.
I am using Docker version 20.10.4, build d3cb89e
.
Any advise what I might be missing?
Currently it's not possible to bind a swarm service to a specific IP. See this more than four year old issue: https://github.com/moby/moby/issues/26696
You can init your swarm with the --advertise-addr
--data-path-addr
and --listen-addr
option bound to your eth1
interface to limit some of the internal swarm traffic to this interface, but this will not really solve the problem.