libnetwork
libnetwork copied to clipboard
same network multiple host interfaces: "failed to allocate gateway (192.168.34.1): Address already in use"
Having two network interfaces connected to the same network:
First network:
$ docker network create -d macvlan \
--subnet 192.168.34.0/24 \
--gateway 192.168.34.1 \
-o parent=eth0 \
--ip-range 192.168.34.2/32 \
eth0-test
2248a7b940e2755a72320b8a58e24a950aa1883b00538930e239b89940cb90c6
Second network:
$ docker network create -d macvlan \
--subnet 192.168.34.0/24 \
--gateway 192.168.34.1 \
-o parent=eth1 \
--ip-range 192.168.34.3/32 \
eth1-test
Error response from daemon: failed to allocate gateway (192.168.34.1): Address already in use
There are related issues: https://github.com/moby/moby/issues/35834 https://github.com/mesg-foundation/core/issues/268
Probably it the cause, in the way that, gateway address is treated as unique, which is not a case. Related issues above, have problem with cleanup for network re-creation. In my case, I need same default gateway for multiple networks explicitly.
When configuration is used for swarm, network create --config-only works for two networks:
Host1:
$ docker network create --config-only \
--subnet 192.168.34.0/24 \
--gateway 192.168.34.1 \
-o parent=eth0 \
--ip-range 192.168.34.2/32 \
eth0-net
378ecbdfc42723cc10205f4d8a1f9dda6d9508066c11005b36c64fccfcccd5dc
$ docker network create --config-only \
--subnet 192.168.34.0/24 \
--gateway 192.168.34.1 \
-o parent=eth1 \
--ip-range 192.168.34.3/32 \
eth1-net
f52e8d6f3a61af51712655ed99b14867a30ae243f49bd6affd7e7839f720b39e
Host2:
$ docker network create --config-only \
--subnet 192.168.34.0/24 \
--gateway 192.168.34.1 \
-o parent=eth0 \
--ip-range 192.168.34.4/32 \
eth0-net
1b34ff55781dee04e14b6907150ffd3d054130cd93d62964ed21d400f3c00358
$ docker network create --config-only \
--subnet 192.168.34.0/24 \
--gateway 192.168.34.1 \
-o parent=eth1 \
--ip-range 192.168.34.5/32 \
eth1-net
91bc6fb5320bbb4546e51b5b46e268779fa4afa471b5191ef81c3e6a4a5f4f29
Host3: omitted
Host-any:
$ docker network create -d macvlan --scope swarm \
--config-from eth0-net eth0-swarm-net
sfulig6iml4t4vhfk1eqzlvnb
$ docker network create -d macvlan --scope swarm \
--config-from eth1-net eth1-swarm-net
79zpw60z6bd3c9giblfv4x1ev
Service fails:
$ docker service create --mode global --name test-service1 \
--network eth0-swarm-net \
--network eth1-swarm-net \
donch/net-tool
judv0bhx3oy2ze3gj89yfwqf2
overall progress: 0 out of 3 tasks
overall progress: 0 out of 3 tasks
overall progress: 0 out of 3 tasks
overall progress: 0 out of 3 tasks
overall progress: 0 out of 3 tasks
furfq6c7v38a: failed to allocate gateway (192.168.34.1): Address already in use
uxsil16voy3o: failed to allocate gateway (192.168.34.1): Address already in use
to2akg3m2sdw: failed to allocate gateway (192.168.34.1): Address already in use
^COperation continuing in background.
Use `docker service ps judv0bhx3oy2ze3gj89yfwqf2` to check progress.