相關概念:nginx
網橋:至關於一個虛擬的交換機,鏈接在此網橋上的全部設備都可以正常通訊;docker
veth pair:虛擬網卡對(2張網卡),兩張網卡之間的收發數據保持一致;bash
docker網絡:
網絡
docker0網橋:在安裝啓動完docker以後,會出現一個docker0的網卡設備(此設備至關於一個交換機);ide
建立docker容器後,會建立2個虛擬網卡,一端顯示在宿主機中,一端是容器中的eth0,這2張網卡是虛擬網卡對;spa
建立2個容器,在宿主機上執行ip a,能夠看到會出現2個虛擬網卡(以veth開頭):ip
docker run -d --name nginx-1 nginx docker run -d --name nginx-2 nginx [root@ks-allinone ~]# ip a ... 3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 02:42:92:a1:07:20 brd ff:ff:ff:ff:ff:ff inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 valid_lft forever preferred_lft forever inet6 fe80::42:92ff:fea1:720/64 scope link valid_lft forever preferred_lft forever 37: veth87e12aa@if36: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default link/ether 56:3f:71:00:b2:95 brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet6 fe80::543f:71ff:fe00:b295/64 scope link valid_lft forever preferred_lft forever 39: vethed473fd@if38: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default link/ether 66:f0:c4:e4:df:a9 brd ff:ff:ff:ff:ff:ff link-netnsid 1 inet6 fe80::64f0:c4ff:fee4:dfa9/64 scope link valid_lft forever preferred_lft forever
brctl show:能夠看到這2個虛擬網卡都綁定在docker0上(至關於經過宿主機上的虛擬網卡鏈接在交換機(docker0)上)it
[root@ks-allinone ~]# brctl show bridge name bridge id STP enabled interfaces docker0 8000.024292a10720 no veth87e12aa vethed473fd
注:鏈接到同一個網橋上以後(至關於鏈接在同一個交換機上),容器之間就能夠進行通訊;ast