如何允许通过macvlan网络启动的容器连接到公共网络

时间:2018-11-16 09:09:41

标签: docker docker-networking macvlan

通过桥接网络启动的容器可以连接到公共网络,并且工作正常。

我的查询-是否可以通过以下设置将通过macvlan网络启动的容器连接到公共网络。

以下是我遵循的步骤。

使用默认网桥nw启动容器。

docker run --rm -dit --name=alpine-bridge alpine ash

ping google以获得公共连接

docker exec alpine-bridge ping -c 2 google.com

PING google.com (172.217.26.206): 56 data bytes
64 bytes from 172.217.26.206: seq=0 ttl=51 time=187.768 ms
64 bytes from 172.217.26.206: seq=1 ttl=51 time=146.569 ms

— google.com ping statistics —
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 146.569/167.168/187.768 ms

主机ifconfig命令输出

连接到wifi网络的主机系统

wlp3s0: flags=4419<UP,BROADCAST,RUNNING,PROMISC,MULTICAST> mtu 1500
inet 192.168.16.138 netmask 255.255.255.0 broadcast 192.168.16.255
inet6 fe80::f72a:652a:147d:7745 prefixlen 64 scopeid 0x20
ether 08:d4:0c:09:56:dc txqueuelen 1000 (Ethernet)
RX packets 250614 bytes 156122122 (156.1 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 250819 bytes 60919158 (60.9 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

创建了一个Macvlan网络,其父节点为wlp3s0

docker network create -d macvlan --subnet=192.168.16.0/24 --gateway=192.168.16.1 -o parent=wlp3s0 pub-net

启动具有桥接网络的容器

docker run --rm -dit --network=pub-net --name=alpine-mac alpine ash

连接性不适用于此设置

docker exec alpine-mac ping -c 2 google.com

PING google.com (216.58.200.142): 56 data bytes

--- google.com ping statistics ---
2 packets transmitted, 0 packets received, 100% packet loss

Docker检查macvlan网络

[
{
“Name”: “pub-net”,
“Id”: “c235ebfe22968f044420b1a9a9fb883395fe66de6e66df457d0c692472d63088”,
“Created”: “2018-11-16T13:32:01.811456245+05:30”,
“Scope”: “local”,
“Driver”: “macvlan”,
“EnableIPv6”: false,
“IPAM”: {
“Driver”: “default”,
“Options”: {},
“Config”: [
{
“Subnet”: “192.168.16.0/24”,
“Gateway”: “192.168.16.1”
}
]
},
“Internal”: false,
“Attachable”: false,
“Ingress”: false,
“ConfigFrom”: {
“Network”: “”
},
“ConfigOnly”: false,
“Containers”: {
“d0473232409f748e8980f52350f24ffc12f390c7eadebb9a41c2943fc6a5e42b”: {
“Name”: “alpine-mac”,
“EndpointID”: “22bb289f706c047748f980310bdf7d381b5cc948c66665303e9435ba3d1fba99”,
“MacAddress”: “02:42:c0:a8:0f:02”,
“IPv4Address”: “192.168.16.2/24”,
“IPv6Address”: “”
}
},
“Options”: {
“parent”: “wlp3s0”
},
“Labels”: {}
}
]

该问题如何解决?

感谢和问候, 莫汉

0 个答案:

没有答案