[英]How to access container from different host on same network when using macvlan driver
I've created my macvlan network as follows: 我创建了如下的macvlan网络:
docker network create -d macvlan -o parent=eth0 \
--subnet 192.168.1.0/24 \
--gateway 192.168.1.1 \
--ip-range 192.168.1.192/27 \
--aux-address 'host=192.168.1.223' \
mynet
I run my container as follows: 我按以下方式运行容器:
docker run --name nginx -d --net mynet nginx
The container's IP is 192.168.1.192 容器的IP为192.168.1.192
I have two hosts that can ping each other both ways: 我有两个可以互相ping通的主机:
Host A: 192.168.1.98 (where Docker engine is running) 主机A:192.168.1.98(运行Docker引擎的地方)
Host B: 192.168.1.6 主机B:192.168.1.6
Because macvlan by definition doesn't allow host-to-container communication, I have created a sub-interface as follows to allow this communication: 由于macvlan按照定义不允许主机到容器的通信,因此我创建了一个如下所示的子接口来允许这种通信:
ip link add mynet-shim link eth0 type macvlan mode bridge
ip addr add 192.168.1.223/32 dev mynet-shim
ip link set mynet-shim up
ip route add 192.168.1.192/27 dev mynet-shim
I'm able to access the container from host A as when I run: 我可以在运行时从主机A访问容器:
curl 192.168.1.192:80
, I receive the nginx default html curl 192.168.1.192:80
,我收到nginx默认html
I'm also able to ping the container from host A. 我还能够从主机A ping容器。
When I run docker logs nginx
, it says: 当我运行docker logs nginx
,它说:
192.168.1.223 - - [02/Nov/2018:16:19:32 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
So it is working with the mynet-shim
sub-interface. 因此,它正在使用mynet-shim
子接口。
However, I'm unable to access the container from host B as both the curl
and ping
commands to the container fail from host B, even though it's in the same subnet as host A and the container 但是,我无法从主机B访问容器,因为从主机B到容器的curl
和ping
命令都失败了,即使它与主机A和容器位于同一子网中
Is there any additional configuration that I may have missed on host B? 我可能在主机B上错过了其他配置吗?
The issue was VMWare's network settings. 问题是VMWare的网络设置。
On VMWare ESXi 6.5 (client version 1.2.3): 在VMWare ESXi 6.5(客户端版本1.2.3)上:
After this, I was able to access the container from a different host on the same network (ie Host B) 之后,我能够从同一网络上的其他主机(即主机B)访问该容器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.