1、创建macVLAN
docker network create -d macvlan --subnet=172.16.86.0/24 --gateway=172.16.86.1 -o parent=ens33 mac_net1
-d macvlan
指定 driver 为 macvlan。
macvlan 网络是 local 网络,为了保证跨主机能够通信,用户需要自己管理 IP subnet。
与其他网络不同,docker 不会为 macvlan 创建网关,这里的网关应该是真实存在的,否则容器无法路由。
-o parent
指定使用的网络 interface。
在 host1 中运行容器 bbox1 并连接到 mac_net1。
2、选择镜像。运行容器并连接到mac_net1
docker run -itd --name bbox1 --ip=172.16.86.10 --network mac_net1 busybox:latest
在另外一台服务器上运行相同的命令 将ip改为172.16.86.10 name修改为bbox2
3、测试
从10向11ping
sub-interface可实现多macvlan网络
完成