Docker中HOST和NONE网络的用途是什么?

前端之家收集整理的这篇文章主要介绍了Docker中HOST和NONE网络的用途是什么?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

试图了解docker网络,Docker自动创建以下网络:

  1. # docker network ls
  2. NETWORK ID NAME DRIVER SCOPE
  3. 67b4afa88032 bridge bridge local
  4. c88f997a2fa7 host host local
  5. 1df2947aad7b none null local

我知道桥接网络代表所有Docker安装中存在的docker0网络,参考link.

有人可以帮助我理解其他网络,主机和没有,如果可能的例子.

Docker默认支持3个网络:

1)没有:

此模式不会为容器配置任何IP,也不能访问外部网络以及其他容器.它具有环回地址,可用于运行批处理作业.

  1. # docker run -it --network=none ubuntu:14.04 /bin/bash
  2. root@66308c6686be:/# ifconfig
  3. lo Link encap:Local Loopback
  4. inet addr:127.0.0.1 Mask:255.0.0.0
  5. UP LOOPBACK RUNNING MTU:65536 Metric:1
  6. RX packets:0 errors:0 dropped:0 overruns:0 frame:0
  7. TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  8. collisions:0 txqueuelen:0
  9. RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
  10. #
  11. # docker inspect 66308c6686be | grep -i ipaddr
  12. "SecondaryIPAddresses": null,"IPAddress": "",

2)主持人

在此模式下,容器将共享主机的网络堆栈,并且主机的所有接口都可供容器使用.容器的主机名将与主机系统上的主机名匹配

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

Even the IP configuration is same as the host system’s IP
configuration

  1. root@labadmin-VirtualBox:/# ip addr | grep -A 2 eth0
  2. 2: eth0: Box:/# exit
  3. exit
  4. HOST SYSTEM IP CONFIGURATION
  5. # ip addr | grep -A 2 eth0
  6. 2: eth0:

在主机和非模式下,未直接配置,但可以配置默认网桥,也可以创建自己的用户定义网桥.

3)桥接模式

它是Docker的默认网络模式,它可以连接到主机的其他接口以及容器之间.

  1. # docker run -it --network=bridge ubuntu:14.04 /bin/bash
  2. root@58b0b1f18b2e:/# ifconfig
  3. eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:0c
  4. inet addr:172.17.0.12 Bcast:0.0.0.0 Mask:255.255.0.0
  5. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  6. RX packets:16 errors:0 dropped:0 overruns:0 frame:0
  7. TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  8. collisions:0 txqueuelen:0
  9. RX bytes:2668 (2.6 KB) TX bytes:0 (0.0 B)
  10. lo Link encap:Local Loopback
  11. inet addr:127.0.0.1 Mask:255.0.0.0
  12. UP LOOPBACK RUNNING MTU:65536 Metric:1
  13. RX packets:0 errors:0 dropped:0 overruns:0 frame:0
  14. TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  15. collisions:0 txqueuelen:0
  16. RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

Accessibility to other containers is possible in bridge mode.

  1. root@58b0b1f18b2e:/# ping 172.17.0.11
  2. PING 172.17.0.11 (172.17.0.11) 56(84) bytes of data.
  3. 64 bytes from 172.17.0.11: icmp_seq=1 ttl=64 time=0.143 ms
  4. 64 bytes from 172.17.0.11: icmp_seq=2 ttl=64 time=0.050 ms

Connectivity to external network.

  1. root@58b0b1f18b2e:/# ping google.com
  2. PING google.com (216.58.197.46) 56(84) bytes of data.
  3. 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

  1. root@labadmin-VirtualBox:~# ip a | grep eth0
  2. 2: eth0:

与这些docker一起提供MACVLAN网络,允许在单个物理接口上配置多个第2层(MAC)地址.

猜你在找的Docker相关文章