问题描述
在使用Docker Desktop for Windows在容器和Windows主机之间进行通信时,丢包率非常高,尤其是对于UDP。
如何摆脱这个问题?
例如,使用以下命令在容器上设置iperf3服务器:
> docker run -it -p 5201:5201 -p 5201:5201/udp --rm alpine:3.10 /bin/sh -c "apk add --no-cache iperf3&&iperf3 -s"
然后检查从Windows主机到容器的UDP吞吐量,看是否丢失了60-80%的数据包。
> .\iperf3.exe -c localhost -u -b 50M
Connecting to host localhost,port 5201
[ 4] local ::1 port 52973 connected to ::1 port 5201
[ ID] Interval Transfer Bandwidth Total Datagrams
[ 4] 0.00-1.01 sec 5.41 MBytes 45.0 Mbits/sec 692
[ 4] 1.01-2.01 sec 5.96 MBytes 49.8 Mbits/sec 763
[...]
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 4] 0.00-10.00 sec 59.1 MBytes 49.6 Mbits/sec 0.515 ms 4718/7558 (62%)
[ 4] Sent 7558 datagrams
iperf Done.
>
> .\iperf3.exe -c localhost -u -b 1G
Connecting to host localhost,port 5201
[ 4] local ::1 port 52974 connected to ::1 port 5201
[ ID] Interval Transfer Bandwidth Total Datagrams
[ 4] 0.00-1.01 sec 111 MBytes 921 Mbits/sec 14172
[ 4] 1.01-2.00 sec 120 MBytes 1.01 Gbits/sec 15405
[...]
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
[ 4] 0.00-10.00 sec 1.16 GBytes 993 Mbits/sec 0.503 ms 124042/151503 (82%)
[ 4] Sent 151503 datagrams
iperf Done.
我在上面以iperf3为例,但是其他使用UDP的通信也会导致性能显着下降。
这在Docker Desctop的稳定版2.3.0.4和Edge 2.3.4.0中都会发生。 无论是否使用WSL 2引擎,都会发生相同的问题。
但是,Docker ToolBox(带有VirtualBox)没有问题。
自Docker Desctop 2.2起,Windows主机与MobyLinuxVM之间的通信已从DockerNAT更改为新机制。 这可能已经影响了这个问题。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)