我有一个包含两个容器的 Docker 网络。当我nping
使用虚假的目标 IP 地址和第二个容器的真实 MAC 地址运行时,输出中出现的数据包tcpdump -eni eth0
具有不同的源地址(MAC 和 IP),并且延迟相当长(约 10 秒)。
这是 Docker 的错误吗,还是我遗漏了什么?
以下是重现该问题的方法。
运行此脚本:
docker network create --driver=bridge --subnet=10.16.17.0/24 so_con
docker run -itd --name=con_A --net=so_con debian /bin/bash
docker run -itd --name=con_B --net=so_con debian /bin/bash
docker exec con_A sh -c 'apt-get update && apt-get install -y tcpdump'
docker exec con_B sh -c 'apt-get update && apt-get install -y nmap'
export A_MAC=`docker inspect -f '{{.NetworkSettings.Networks.so_con.MacAddress}}' con_A`
docker exec con_B nping -c 100 --rate 1 --dest-mac $A_MAC 2.15.9.20 &
docker exec con_A tcpdump -eni eth0
在完成安装数据包后apt-get
,您将看到nping
和的混合输出tcpdump
:
Starting Nping 0.6.47 ( http://nmap.org/nping ) at 2016-01-07 16:35 UTC
SENT (0.0331s) ICMP [10.16.17.3 > 2.15.9.20 Echo request (type=8/code=0) id=6585 seq=1] IP [ttl=64 id=3571 iplen=28 ]
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
SENT (1.0336s) ICMP [10.16.17.3 > 2.15.9.20 Echo request (type=8/code=0) id=6585 seq=3] IP [ttl=64 id=3571 iplen=28 ]
SENT (2.0351s) ICMP [10.16.17.3 > 2.15.9.20 Echo request (type=8/code=0) id=6585 seq=3] IP [ttl=64 id=3571 iplen=28 ]
SENT (3.0366s) ICMP [10.16.17.3 > 2.15.9.20 Echo request (type=8/code=0) id=6585 seq=4] IP [ttl=64 id=3571 iplen=28 ]
SENT (4.0381s) ICMP [10.16.17.3 > 2.15.9.20 Echo request (type=8/code=0) id=6585 seq=5] IP [ttl=64 id=3571 iplen=28 ]
SENT (5.0396s) ICMP [10.16.17.3 > 2.15.9.20 Echo request (type=8/code=0) id=6585 seq=6] IP [ttl=64 id=3571 iplen=28 ]
SENT (6.0410s) ICMP [10.16.17.3 > 2.15.9.20 Echo request (type=8/code=0) id=6585 seq=7] IP [ttl=64 id=3571 iplen=28 ]
SENT (7.0419s) ICMP [10.16.17.3 > 2.15.9.20 Echo request (type=8/code=0) id=6585 seq=8] IP [ttl=64 id=3571 iplen=28 ]
SENT (8.0433s) ICMP [10.16.17.3 > 2.15.9.20 Echo request (type=8/code=0) id=6585 seq=9] IP [ttl=64 id=3571 iplen=28 ]
SENT (9.0447s) ICMP [10.16.17.3 > 2.15.9.20 Echo request (type=8/code=0) id=6585 seq=10] IP [ttl=64 id=3571 iplen=28 ]
16:36:00.699670 02:42:0a:10:11:03 > 02:42:0a:10:11:02, ethertype IPv4 (0x0800), length 42: 10.16.17.1 > 2.15.9.20: ICMP echo request, id 6585, seq 3, length 8
16:36:00.699764 02:42:0a:10:11:02 > 02:42:1b:a1:db:5a, ethertype IPv4 (0x0800), length 70: 10.16.17.2 > 10.16.17.1: ICMP redirect 2.15.9.20 to host 10.16.17.1, length 36
16:36:00.699809 02:42:0a:10:11:02 > 02:42:1b:a1:db:5a, ethertype IPv4 (0x0800), length 42: 10.16.17.1 > 2.15.9.20: ICMP echo request, id 6585, seq 3, length 8
16:36:01.701244 02:42:0a:10:11:03 > 02:42:0a:10:11:02, ethertype IPv4 (0x0800), length 42: 10.16.17.1 > 2.15.9.20: ICMP echo request, id 6585, seq 3, length 8
这里有两点观察:
tcpdump
经过一段时间(9 秒)后才收到第一个包裹。接收到的包来自连接到主机的 Docker 特殊桥接接口,在我的情况下是:
br-436234216b46 Link encap:Ethernet HWaddr 02:42:1b:a1:db:5a inet addr:10.16.17.1 Bcast:0.0.0.0 Mask:255.255.255.0
另外,如果您tcpdump
在上述主机绑定接口上运行br-436234216b46
,它将显示由于某种原因nping
来自con_B
它的原始包,而不是con_A
。
我用Docker 1.9.1
在 64 位上Ubuntu 14.04
。