Skip to main content
 首页 » 编程设计

networking之如何更改 docker swarm 入口网络的 IP 地址范围

2024年10月24日23soundcode

我使用 docker swarm 1.13.1,当我初始化 docker swarm 或加入 docker swarm 时,它有时会在“172.19.0.0/16”子网中创建一个 docker_gwbridge 网络。

但是我的计算机子网在相同的范围内,所以当它初始化这个网络时,docker swarm 主机变得无法从我的计算机访问。

所以我的问题是:如何更改现有 docker 网络的子网。

> docker network ls 
NETWORK ID          NAME                DRIVER              SCOPE 
ac1100164960        bridge              bridge              local 
3838ae360f35        docker_gwbridge     bridge              local 
f9a77266aa15        host                host                local 
rgqnm19zbasv        ingress             overlay             swarm 
04c1c6b3ade7        none                null                local 

检查网络:
> docker network inspect 3838ae360f35 
[ 
    { 
        "Name": "docker_gwbridge", 
        "Id": "3838ae360f3585f2cda8a43a939643cdd74c0db9bfb7f4f18b3b80ae07b3b9db", 
        "Created": "2017-03-22T13:26:50.352865644+01:00", 
        "Scope": "local", 
        "Driver": "bridge", 
        "EnableIPv6": false, 
        "IPAM": { 
            "Driver": "default", 
            "Options": null, 
            "Config": [ 
                { 
                    "Subnet": "172.19.0.0/16", 
                    "Gateway": "172.19.0.1" 
                } 
            ] 
        }, 
        "Internal": false, 
        "Attachable": false, 
        "Containers": { 
            "ingress-sbox": { 
                "Name": "gateway_ingress-sbox", 
                "EndpointID": "194d965dd2997bddb52eab636950e219043215a5a1a6a60d08f34e454a0eaa56", 
                "MacAddress": "02:42:ac:13:00:02", 
                "IPv4Address": "172.19.0.2/16", 
                "IPv6Address": "" 
            } 
        }, 
        "Options": { 
            "com.docker.network.bridge.enable_icc": "false", 
            "com.docker.network.bridge.enable_ip_masquerade": "true", 
            "com.docker.network.bridge.name": "docker_gwbridge" 
        }, 
        "Labels": {} 
    } 
] 

请您参考如下方法:

您可以创建 docker_gwbridge在初始化群之前,如 explained here .
例如:

docker network rm docker_gwbridge 
docker network create --subnet=172.20.0.1/16 -o com.docker.network.bridge.enable_icc=false -o com.docker.network.bridge.name=docker_gwbridge docker_gwbridge