Docker Swarm 将端口绑定到所有主机接口

Docker Swarm 将端口绑定到所有主机接口

主机有以下网络接口:

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:b5:1e:5a:50  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

docker_gwbridge: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.18.0.1  netmask 255.255.0.0  broadcast 172.18.255.255
        inet6 fe80::42:36ff:feae:7b45  prefixlen 64  scopeid 0x20<link>
        ether 02:42:36:ae:7b:45  txqueuelen 0  (Ethernet)
        RX packets 226939106  bytes 46241924181 (43.0 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 166  bytes 8300 (8.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 1.1.1.1  netmask 255.255.255.0  broadcast 1.1.1.255
        inet6 fe80::21a:ff:fe00:43f  prefixlen 64  scopeid 0x20<link>
        ether 00:1a:00:00:04:3f  txqueuelen 1000  (Ethernet)
        RX packets 3852423  bytes 1206323488 (1.1 GiB)
        RX errors 0  dropped 11  overruns 0  frame 0
        TX packets 380930  bytes 85160453 (81.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 2.2.2.2  netmask 255.255.255.0  broadcast 2.2.2.255
        inet6 fe80::21a:ff:fe00:b1a  prefixlen 64  scopeid 0x20<link>
        ether 00:1a:00:00:0b:1a  txqueuelen 1000  (Ethernet)
        RX packets 226939106  bytes 46241924181 (43.0 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 166  bytes 8300 (8.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

在 swarm docker compose config 中,我将所有接口的 162 端口绑定到容器中的 162 端口:

    ports:
      - target: 162
        published: 162
        protocol: udp
        mode: host
    networks:
      - default

所有端口绑定看起来都很好:docker ps -a

80/tcp, 0.0.0.0:162->162/udp, :::162->162/udp

当我将 udp 数据包发送到 eth0 ( 1.1.1.1 ) 时,我通过 tcpdump 在容器中捕获此数据包。当我将 udp 数据包发送到 eth1 ( 2.2.2.2 ) 时,我没有在容器中捕获该数据包。

我如何从 eth1 捕获容器中的数据包?

相关内容