[英]Docker container loses packets in macvlan network
I'm trying to dockerize a project including python server that needs to communicate with several devices on local network. 我正在尝试对包括python服务器的项目进行泊坞化,该项目需要与本地网络上的多个设备进行通信。 For that i'm using a user-defined macvlan network.
为此,我正在使用用户定义的macvlan网络。 Project also includes postgresql database and web application which communicate over default overlay network.
项目还包括通过默认覆盖网络进行通信的postgresql数据库和Web应用程序。
I created macvlan network using commands below: 我使用以下命令创建了macvlan网络:
docker network create --config-only --subnet 10.10.10.0/24 --gateway 10.10.10.1 -o parent=eth0 macvlan_conf
docker network create --config-from macvlan_conf --scope swarm -d macvlan public
Then I deployed our project using this .yml file 然后,我使用此.yml文件部署了我们的项目
version: '3'
services:
db:
image: db_image
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: mt
networks:
- default
ports:
- 9432:5432
mtwa:
image: mtwa_image
networks:
- default
ports:
- 9090:8090
mtrest:
image: mtrest_image
networks:
- default
ports:
- 9091:8091
mtss:
image: mtss_image
networks:
- default
- public
ports:
- 55555:55555
nginx:
image: nginx_image
networks:
- default
ports:
- 9080:80
networks:
public:
external:
name: public
Problem is that from the container with python server (mtss) I have extreme packet loss (over 90%) when I try to ping any device on the local network. 问题是当尝试对本地网络上的任何设备执行ping操作时,带有python服务器(mtss)的容器的数据包丢失率极高(超过90%)。
The rest of communication between other containers or between devices on the local network is just fine. 其他容器之间或本地网络上的设备之间的其余通信都很好。
Wierdest part is that if i restart the container with python server: 最奇怪的是,如果我用python服务器重启容器:
docker restart <Container ID>
Docker stops one container but then it starts two copies of python server where one of them still has poor connection but the second one works flawlessly. Docker停止了一个容器,但随后启动了两个python服务器副本,其中一个副本仍然连接不良,而第二个副本则正常运行。
I'm working on machine with Ubuntu 16.04 and Docker version 18.05.0-ce 我正在使用Ubuntu 16.04和Docker 18.05.0-ce的计算机上工作
Any ideas what could cause the problem? 有什么想法会导致问题吗?
Ok, so I found out that the problem was a conflict in IP addresses. 好的,所以我发现问题出在IP地址冲突。 Services in swarm mode connected to macvlan aren't able to use DHCP neither thay can be assigned a static IP address ( https://forums.docker.com/t/docker-swarm-1-13-static-ips-for-containers/28060/4 )
以群集模式连接到macvlan的服务无法使用DHCP,也无法为它们分配静态IP地址( https://forums.docker.com/t/docker-swarm-1-13-static-ips-for-容器/ 28060/4 )
So I wrote a bash script that starts containers individually. 因此,我写了一个bash脚本来单独启动容器。 Everything works now but i lost the extra functionality of swarm mode.
现在一切正常,但是我失去了群集模式的额外功能。
Hope this saves time to everyone facing similar problems. 希望这可以为面临类似问题的每个人节省时间。
That's how i solved the issue (Docker-CE 18.06). 这就是我解决问题的方式(Docker-CE 18.06)。 I have 3 manager nodes: host1 , host2 and host3
我有3个管理器节点: host1 , host2和host3
I created different config-only network at each node 我在每个节点上创建了不同的仅配置网络
host1 : host1 :
$ docker network create --opt parent=ens18 --subnet=10.19.10.0/23 --gateway=10.19.11.1 --ip-range=19.19.10.0/29 --config-only macvlan_conf
host2 : host2 :
$ docker network create --opt parent=ens18 --subnet=10.19.10.0/23 --gateway=10.19.11.1 --ip-range=19.19.10.8/29 --config-only macvlan_conf
host3 : host3 :
$ docker network create --opt parent=ens18 --subnet=10.19.10.0/23 --gateway=10.19.11.1 --ip-range=19.19.10.16/29 --config-only macvlan_conf
Then I created a swarm-scope network at host1: 然后,我在host1上创建了一个范围广泛的网络:
$ docker network create --config-from=macvlan_conf --driver=macvlan --scope=swarm macvlan_net
So now docker IPAM driver isn't confused by the same ip-range on three nodes: 因此,现在Docker IPAM驱动程序不再被三个节点上的相同ip范围所混淆:
host2 | SUCCESS | rc=0 >>
d78f4fba4fcc
"IPAddress": "10.19.10.8",
host3 | SUCCESS | rc=0 >>
9ee40555f1c8
"IPAddress": "10.19.10.16",
host1 | SUCCESS | rc=0 >>
be76266d7180
"IPAddress": "10.19.10.2",
1052f0a8de1e
"IPAddress": "10.19.10.1",
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.