【问题标题】:Docker Swarm container with MACVLAN network gets wrong gateway - no internet access具有 MACVLAN 网络的 Docker Swarm 容器获取错误的网关 - 无法访问互联网
【发布时间】:2017-10-01 21:56:30
【问题描述】:

我需要一个 Docker Swarm 堆栈中的服务,它有一个基于 macvlan 网络的附加接口。这是因为此服务中的 JBoss Cluster 需要通过 IP 多播进行通信,而覆盖网络目前不支持。

我已经创建了这样的macvlan 网络:

# 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

多播就这样完美地工作,集群形式。

但是: 一旦我将这个macvlan 网络分配给我的一个容器,这个容器就不能再访问互联网。 所有没有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,它来自macvlan 网络的范围,但不存在。这是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

具有有效互联网访问权限的容器,例如petshop-backend172.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

【问题讨论】:

  • external_access: driver: overlay internal: false移动到底部,它可能会起作用
  • @TarunLalwani - 完美的作品。虽然这似乎不是很透明。非常感谢!

标签: docker docker-swarm docker-networking


【解决方案1】:

你需要改变

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

目前似乎最后一个连接的网络接管了网关路由。同样有一个未解决的问题

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

【讨论】:

    猜你喜欢
    • 2017-06-24
    • 1970-01-01
    • 2019-08-23
    • 2016-02-20
    • 1970-01-01
    • 2020-10-18
    • 2018-05-01
    • 2014-07-11
    • 2021-09-23
    相关资源
    最近更新 更多