具有MACVLANnetworking的Docker Swarm容器得到错误的网关 – 没有互联网访问

我需要一个Docker Swarm堆栈中的服务,它有一个基于macvlannetworking的附加接口。 这是因为这个服务中的JBoss集群需要通过IP组播来进行通信,这个组播在覆盖networking中目前是不支持的。

我创build了这样的macvlannetworking:

 # Worker 1: docker network create --config-only --subnet 10.140.0.0/16 -o parent=ens224.800 --ip-range 10.140.1.0/24 swarm-multicast-config-only # Worker 2: docker network create --config-only --subnet 10.140.0.0/16 -o parent=ens224.800 --ip-range 10.140.2.0/24 swarm-multicast-config-only # Worker 3: docker network create --config-only --subnet 10.140.0.0/16 -o parent=ens224.800 --ip-range 10.140.3.0/24 swarm-multicast-config-only # Master: docker network create -d macvlan --scope swarm --internal --config-from swarm-multicast-config-only swarm-multicast 

多播工作完美的那样,集群forms。

但是:只要我将这个macvlannetworking分配给我的一个容器,这个容器就不能再访问互联网了。 所有没有macvlannetworking的容器macvlan正常工作。

这是我的堆栈文件:

 version: '3.3' services: ### Backend ### petshop-backend: image: com-registry.xxx.local/petshop-backend:100 extra_hosts: - "petshop-db:10.164.210.214" networks: - backend - external_access deploy: mode: replicated replicas: 3 ### USER INTERFACE ### petshop-ui: image: com-registry.xxx.local/petshop-ui:107 networks: external_access: backend: swarm-multicast: aliases: - ui-multicast ports: - "1002:8080" deploy: mode: replicated replicas: 3 networks: external_access: driver: overlay internal: false backend: driver: overlay internal: true swarm-multicast: external: true 

如何启用petshop-ui的容器访问互联网? 他们得到一个默认网关10.140.1.0,这是从macvlannetworking的范围,但不存在。 这里是一个petshop-ui容器的路由表:

 [root@f477c7cb8048 /]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.140.1.0 0.0.0.0 UG 0 0 0 eth2 10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth4 10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 10.140.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2 10.255.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth3 

具有上网function的容器,例如petshop-backend ,默认网关为172.18.0.1 。 这是一个这样的路由表:

 [root@ddb42ef836f3 /]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 172.18.0.1 0.0.0.0 UG 0 0 0 eth2 10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2 

你需要改变

 networks: external_access: driver: overlay internal: false backend: driver: overlay internal: true swarm-multicast: external: true 

 networks: backend: driver: overlay internal: true swarm-multicast: external: true external_access: driver: overlay internal: false 

目前看来最后一个networking接pipe了网关路由。 对此也有一个公开的问题

https://github.com/moby/moby/issues/20179