docker中自定ingress网络

在某些时候,docker自动生成的ingress网络会与服务器上已经存在的网络产生冲突,这个时候,你需要自定义ingress。

在自定义前,你需要删除所有有端口发布的服务。

  1. 使用命令docker network inspect ingress查看所有连接到网络的服务,并停止所有的服务,否则,下一步操作将会失败。

  2. Remove the existing ingress network:

$ docker network rm ingress

WARNING! Before removing the routing-mesh network, make sure all the nodes
in your swarm run the same docker engine version. Otherwise, removal may not
be effective and functionality of newly create ingress networks will be
impaired.
Are you sure you want to continue? [y/N]
  1. 使用--ingress选项创建一个新的ingress网络,并设置新的子网信息等。
$ docker network create 
  -d overlay 
  --ingress 
  --subnet=10.11.0.0/16 
  --gateway=10.11.0.2 
  --opt com.docker.network.mtu=1200 
  my-ingress

Note: You can name your ingress network something other than ingress, but you can only have one. An attempt to create a second one will fail.

  1. 重启刚才停止的服务

该功能公支持docker 17.05及以后版本

原文地址:https://www.cnblogs.com/zsea/p/7047669.html