第 8 章 容器网络 - 055 - 创建 macvlan 网络

1、创建 macvlan 网络

 

在 host1 和 host2 中创建 macvlan 网络 mac_net1:

docker network create -d macvlan --subnet=172.16.86.0/24 --gateway=172.16.86.1 -o parent=ens192 mac_net1

 

 

注意:在 host2 中也要执行相同的命令。

1) -d macvlan 指定 driver 为 macvlan。

2) macvlan 网络是 local 网络,为了保证跨主机能够通信,用户需要自己管理 IP subnet。

3) 与其他网络不同,docker 不会为 macvlan 创建网关,这里的网关应该是真实存在的,否则容器无法路由。

4) -o parent 指定使用的网络 interface。

 

在 host1 中运行容器 bbox1 并连接到 mac_net1。

由于 host1 中的 mac_net1 与 host2 中的 mac_net1 本质上是独立的,为了避免自动分配造成 IP 冲突,我们最好通过 --ip 指定 bbox1 地址为 172.16.86.10。

docker run -itd --name bbox1 --ip=172.16.86.10 --network mac_net1 busybox

在 host2 中运行容器 bbox2,指定 IP 172.16.86.11。

docker run -itd --name  bbox2 --ip=172.16.86.11 --network mac_net1 busybox

验证 bbox1 和 bbox1 的连通性。

 

bbox2 能够 ping 到 bbox1 的 IP 172.16.86.10,但无法解析 “bbox1” 主机名。

可见 docker 没有为 macvlan 提供 DNS 服务,这点与 overlay 网络是不同的。

 

-----------------------------------------引用来自---------------------------------------------------

https://mp.weixin.qq.com/s?__biz=MzIwMTM5MjUwMg==&mid=2653587785&idx=1&sn=f04daf7ceb281fce4bcc7e7d45d1255d&chksm=8d308150ba470846d9c9c927f035ef296375791f553c54891fbc9ea486ae5e0958c513dbc272&scene=21#wechat_redirect

猜你喜欢

转载自www.cnblogs.com/gsophy/p/10578653.html