docker的网络配置

容器的网络配置

下面一些参数是在执行docker run时,提供给具体容器的:
--net=bridge/none/container/host

  • 'bridge': creates a new network stack for the container on the docker bridge

  • 'none': no networking for this container

  • 'container:<name|id>': reuses another container network stack

  • 'host': use the host network stack inside the container. Note: the host mode gives the container full access to local system services such as D-bus and is therefore considered insecure.

net

--net用于指定容器使用的网络通信方式,它可以取下面四个值:

  • bridge:这个Docker中的容器默认的方式

  • none:容器没有网络栈,也就是说容器无法与外部通信。

  • container:<name|id>:使用其他容器(name或者id指定)的网络栈。实际上,Docker会将该容器加入指定容器的network namespace,这是一种非常有用的方式。

  • host:表示容器使用Host的网络,没有自己独立的网络栈。实际上,在这种情况下,Docker不会给容器创建单独的网络名字空间(network namespace)。由于容器可以完全访问Host的网络,所以此方式也是不安全的。

评论

暂无评论