docker中HOST和NONEnetworking的用途是什么?

试图了解dockernetworking,Docker自动创build以下networking:

# docker network ls NETWORK ID NAME DRIVER SCOPE 67b4afa88032 bridge bridge local c88f997a2fa7 host host local 1df2947aad7b none null local 

我了解到桥接networking代表所有Docker安装中存在的docker0networking,从链接中引用。

有人可以帮助我理解其他networking, 主机没有 ,如果可能的话与例子。

Docker 默认支持3个networking

1)没有限制

此模式不会为容器configuration任何IP,并且不能访问外部networking以及其他容器 。 它具有环回地址,可用于运行批处理作业。

 # 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": "", "IPAddress": "", 

2)主持人

在这种模式下, 容器将共享主机的networking堆栈,主机的所有接口都将可用于容器 。 容器的主机名将与主机系统上的主机名匹配

 # docker run -it --net=host ubuntu:14.04 /bin/bash root@labadmin-VirtualBox:/# hostname labadmin-VirtualBox 

即使IPconfiguration与主机系统的IPconfiguration相同

 root@labadmin-VirtualBox:/# ip addr | grep -A 2 eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:b5:82:2f brd ff:ff:ff:ff:ff:ff inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 valid_lft forever preferred_lft forever 3: lxcbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default root@labadmin-VirtualBox:/# exit exit HOST SYSTEM IP CONFIGURATION # ip addr | grep -A 2 eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:b5:82:2f brd ff:ff:ff:ff:ff:ff inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 valid_lft forever preferred_lft forever 3: lxcbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default 

在主机和非模式不直接configuration,但可以configuration默认网桥networking,以及创build自己的用户定义桥networking。

3)桥接模式

这是Docker默认的networking模式,可以连接到主机的其他接口以及容器之间

 # 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) 

在桥接模式下可以访问其他容器。

 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 

连接到外部networking。

 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 

连接到主机

 root@labadmin-VirtualBox:~# ip a | grep eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 root@58b0b1f18b2e:/# ping 10.0.2.15 PING 10.0.2.15 (10.0.2.15) 56(84) bytes of data. 64 bytes from 10.0.2.15: icmp_seq=1 ttl=64 time=0.113 ms 

随着这些docker提供了MACVLANnetworking,它允许在单个物理接口上configuration多个第2层(MAC)地址。

假设你的docker镜像支持ifconfig,镜像名称是“ubuntu / net”

然后,运行docker for hostnone

 sudo docker run -it --network=host ubuntu/net root@localhost:/# ifconfig docker0 Link encap:Ethernet HWaddr xxxxxxxxxxxxx inet addr:xxxx Bcast:0.0.0.0 Mask:255.255.0.0 eth0 Link encap:Ethernet HWaddr xxxxxxxxxxxx inet addr:yyyy Bcast: Mask:255.255.254.0 sudo docker run -it --network=none ubuntu/net root@localhost:/# ifconfig lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0