主要参考天天5分钟玩转docker容器技术博客。 记录下本身的实验过程。 若是想学习,请直接参考该博客http://www.cnblogs.com/CloudMan6/
咱们使用host2与host3上单独的网卡enp0s8建立macvlan。
为保证多个 MAC 地址的网络包均可以从 enp0s9 经过,咱们须要打开网卡的混杂模式。
混杂模式简介docker
首先在/etc/network/interfaces文件中添加以下内容网络
auto enp0s8 iface enp0s8 inet dhcp
确认网卡PROMISC已经生效,且网卡up学习
root@host2:~# ip link set enp0s8 promisc on root@host2:~# /etc/init.d/networking restart [ ok ] Restarting networking (via systemctl): networking.service. root@host2:~# ip a |grep -A3 enp0s8 3: enp0s8: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:43:fd:30 brd ff:ff:ff:ff:ff:ff inet 192.168.56.101/24 brd 192.168.56.255 scope global enp0s8 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe43:fd30/64 scope link valid_lft forever preferred_lft forever
在host2与host3上执行下面的语句spa
root@host2:~# docker network create -d macvlan \ > --subnet=172.16.86.0/24 \ > --gateway=172.16.86.1 \ > -o parent=enp0s8 mac_net1 9e831209515c38d091f7fc10265fed7f995f49ec6acd9cb22c7b2c83c5819d97
在host2运行容器bbox1 并链接至mac_net13d
root@host2:~# docker run -itd --name bbox1 --ip=172.16.86.10 --network mac_net1 busybox 06d1244098d1d0a8eac41cdc8505d6f145b86b55161603014c2247bd84cae939
在host3中运行bbox2, 并链接至mac_net2rest
root@host3:~# docker run -itd --name bbox2 --ip=172.16.86.11 --network mac_net1 busybox b033f3ad107eeb18e93f130bd1add171874b9ad54325f5d24ff58ac79cac183d
为了不自动分配形成ip冲突,建立时最好指定ipcode
root@host2:~# docker exec -it bbox1 ping -c 2 172.16.86.10 PING 172.16.86.10 (172.16.86.10): 56 data bytes 64 bytes from 172.16.86.10: seq=0 ttl=64 time=0.108 ms ^C --- 172.16.86.10 ping statistics --- 1 packets transmitted, 1 packets received, 0% packet loss round-trip min/avg/max = 0.108/0.108/0.108 ms root@host2:~# docker exec -it bbox1 ping -c 2 172.16.86.11 PING 172.16.86.11 (172.16.86.11): 56 data bytes 64 bytes from 172.16.86.11: seq=0 ttl=64 time=1.345 ms 64 bytes from 172.16.86.11: seq=1 ttl=64 time=1.116 ms --- 172.16.86.11 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 1.116/1.230/1.345 ms
可是没法解析主机名blog