试图了解docker网络,Docker自动创建以下网络:
# docker network ls
NETWORK ID NAME DRIVER SCOPE
67b4afa88032 bridge bridge local
c88f997a2fa7 host host local
1df2947aad7b none null local
我知道桥接网络代表所有Docker安装中存在的docker0网络,参考link.
有人可以帮助我理解其他网络,主机和没有,如果可能的例子.
Docker默认支持3个网络:
1)没有:
此模式不会为容器配置任何IP,也不能访问外部网络以及其他容器.它具有环回地址,可用于运行批处理作业.
# docker run -it --network=none ubuntu:14.04 /bin/bash
root@66308c6686be:/# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
#
# docker inspect 66308c6686be | grep -i ipaddr
"SecondaryIPAddresses": null,"IPAddress": "",
2)主持人
在此模式下,容器将共享主机的网络堆栈,并且主机的所有接口都可供容器使用.容器的主机名将与主机系统上的主机名匹配
# docker run -it --net=host ubuntu:14.04 /bin/bash
root@labadmin-VirtualBox:/# hostname
labadmin-VirtualBox
Even the IP configuration is same as the host system’s IP
configuration
root@labadmin-VirtualBox:/# ip addr | grep -A 2 eth0
2: eth0: Box:/# exit
exit
HOST SYSTEM IP CONFIGURATION
# ip addr | grep -A 2 eth0
2: eth0:
在主机和非模式下,未直接配置,但可以配置默认网桥,也可以创建自己的用户定义网桥.
3)桥接模式
它是Docker的默认网络模式,它可以连接到主机的其他接口以及容器之间.
# docker run -it --network=bridge ubuntu:14.04 /bin/bash
root@58b0b1f18b2e:/# ifconfig
eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:0c
inet addr:172.17.0.12 Bcast:0.0.0.0 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:16 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2668 (2.6 KB) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Accessibility to other containers is possible in bridge mode.
root@58b0b1f18b2e:/# ping 172.17.0.11
PING 172.17.0.11 (172.17.0.11) 56(84) bytes of data.
64 bytes from 172.17.0.11: icmp_seq=1 ttl=64 time=0.143 ms
64 bytes from 172.17.0.11: icmp_seq=2 ttl=64 time=0.050 ms
Connectivity to external network.
root@58b0b1f18b2e:/# ping google.com
PING google.com (216.58.197.46) 56(84) bytes of data.
64 bytes from maa03s20-in-f46.1e100.net (216.58.197.46): icmp_seq=1 ttl=51 time=16.9 ms
Connectivity to host machine
root@labadmin-VirtualBox:~# ip a | grep eth0
2: eth0:
与这些docker一起提供MACVLAN网络,允许在单个物理接口上配置多个第2层(MAC)地址.