(八)創建 macvlan 網路
上一節我們準備好了 macvlan 的實驗環境,今天在 host1 和 host2 中創建 macvlan 網路 mac_net1:
root@host1:~# docker network create -d macvlan --subnet=172.16.86.0/24 --gateway=172.16.86.1 -o parent=ens38 mac_net1
3ed6d6fe61b21271575c9edfe1f1e8a7991d8428939d301d1c4d71559d5bece8
注意:在 host2 中也要執行相同的命令,
① -d macvlan 指定 driver 為 macvlan,
② macvlan 網路是 local 網路,為了保證跨主機能夠通信,用戶需要自己管理 IP subnet,
③ 與其他網路不同,docker 不會為 macvlan 創建網關,這里的網關應該是真實存在的,否則容器無法路由,
④ -o parent 指定使用的網路 interface,
在 host1 中運行容器 bbox10 并連接到 mac_net1,
root@host1:~# docker run -itd --name bbox10 --ip=172.16.86.100 --network mac_net1 busybox
1e5dbb897e7e8b0dc3d9e8f92ceb4face61c96e0495691e3a2c8faee47836883
root@host1:~#
由于 host1 中的 mac_net1 與 host2 中的 mac_net1 本質上是獨立的,為了避免自動分配造成 IP 沖突,我們最好通過 --ip 指定 bbox10 地址為 172.16.86.100,
在 host2 中運行容器 bbox11,指定 IP 172.16.86.11,
root@host2:~# docker run -itd --name bbox11 --ip=172.16.86.11 --network mac_net1 busybox
812e38fd15a355de13d7705b6e9ea001cc7e34b290e73c4ed320e010b3c49bd7
root@host2:~#
驗證 bbox11 和 bbox10 的連通性,
root@host2:~# docker exec bbox11 ping -c 2 172.16.86.100
PING 172.16.86.10 (172.16.86.10): 56 data bytes
64 bytes from 172.16.86.100: seq=0 ttl=64 time=0.584 ms
64 bytes from 172.16.86.100: seq=1 ttl=64 time=0.396 ms
--- 172.16.86.10 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.396/0.490/0.584 ms
root@host2:~#
bbox2 能夠 ping 到 bbox10 的 IP 172.16.86.100,但無法決議 “bbox10” 主機名,
root@host2:~# docker exec bbox11 ping -c 2 bbox10
ping: bad address 'bbox100'
root@host2:~#
可見 docker 沒有為 macvlan 提供 DNS 服務,這點與 overlay 網路是不同的,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/231840.html
標籤:其他
上一篇:Kubernetes 教程:在 Containerd 容器中使用 GPU
下一篇:揭秘 VMAF 視頻質量評測標準
