【发布时间】:2017-06-24 07:48:12
【问题描述】:
我有一个具有多个 IP 地址的专用服务器,一些 IP 具有关联的 MAC 地址,而其他(在子网中)没有 MAC 地址。 我使用以下方法创建了 docker macvlan 网络:
docker network create -d macvlan -o macvlan_mode=bridge --subnet=188.40.76.0/26 --gateway=188.40.76.1 -o parent=eth0 macvlan_bridge
我有 ip:88.99.102.115 和 mac:00:50:56:00:60:42。使用以下方法创建了一个容器:
docker run --name cont1 --net=macvlan_bridge --ip=88.99.102.115 --mac-address 00:50:56:00:60:42 -itd nginx
这可行,我可以从外部访问托管在该 IP 地址的 nginx。
IP无mac地址且网关不在子网内的情况。
子网:88.99.114.16/28,网关:88.99.102.103
无法使用以下方式创建网络:
docker network create -d macvlan -o macvlan_mode=bridge --subnet=88.99.114.16/28 --gateway=88.99.102.103 -o parent=eth0 mynetwork
抛出错误:
no matching subnet for gateway 88.99.102.103
尝试增加子网范围以包括网关:
docker network create -d macvlan -o macvlan_mode=bridge --subnet=88.99.0.0/16 --gateway=88.99.102.103 -o parent=eth0 mynetwork
创建了网络,然后使用“mynetwork”启动了 nginx 容器,而且我没有 88.99.114.18 的 mac 地址,所以使用了一些随机的 mac 地址 40:1c:0f:bd:a1:d2。
docker run --name cont1 --net=mynetwork --ip=88.99.114.18 --mac-address 40:1c:0f:bd:a1:d2 -itd nginx
无法访问 nginx(88.99.102.115)。
- 如果我的网关不在我的子网中,如何创建 macvlan docker 网络?
- 当我只有 IP 地址而没有 mac 地址时,如何使用 macvlan 网络运行容器?
我对网络的了解不多,如果你详细解释一下会很有帮助的。
我的 /etc/network/interfaces 文件:
### Hetzner Online GmbH - installimage
# Loopback device:
auto lo
iface lo inet loopback
iface lo inet6 loopback
# device: eth0
auto eth0
iface eth0 inet static
address 88.99.102.103
netmask 255.255.255.192
gateway 88.99.102.65
# default route to access subnet
up route add -net 88.99.102.64 netmask 255.255.255.192 gw 88.99.102.65 eth0
iface eth0 inet6 static
address 2a01:4f8:221:1266::2
netmask 64
gateway fe80::1
【问题讨论】:
-
IP 和子网是如何分配给您的?您需要该子网中的网关为数据包提供路由,同样重要的是,为其他网络提供返回子网的路由。
标签: linux networking docker containers