本文主要介绍当安装或启动 Docker 服务时默认使用的网桥BIP地址跟主机上其它网卡所在的网段起冲突时,如何修改 Docker 服务的默认网桥地址。
详细说明
目前通过 oat-all-in-one-<arch>-<version>.tar 包解压文件中的 install.sh 脚本部署出来的 Docker 服务默认使用的网桥 BIP 地址都是 172.17.0.1/16,如下图所示。

但是如果客户其它网卡的网段跟 172.17.0.1/16 有重叠的话,就会带来下面两个副作用:
Docker 服务启动失败。
安装完 Docker 服务后,原来可以正常连通的 IP(比如
172.17.xxx.xxx/24网段的两个 IP 地址)相互之间不能 ping 通了。
为了解决上述问题,需要手动修改 Docker 服务默认使用的网桥地址 BIP。具体步骤如下。
检查当前 Docker 服务的 Service 配置文件。
root@oat-server:~# systemctl status docker -l --no-pager ● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2025-06-11 11:32:08 CST; 1 week 0 days ago Docs: http://docs.docker.com Main PID: 1018 (dockerd) Tasks: 127 (limit: 115726) Memory: 1.9G CPU: 26min 5.056s CGroup: /system.slice/docker.service ├─ 1018 /usr/bin/dockerd --bip=172.17.0.1/16 -H unix:///var/run/docker.sock --selinux-enabled=false --log-opt max-size=1g --data-root=/docker --live-restore ├─ 1320 containerd --config /var/run/docker/containerd/containerd.toml --log-level info ├─ 1813 /usr/bin/containerd-shim-runc-v2 -namespace moby -id 6e65cbbabcb4239485b54d45452ee9c7755a2548c00342bd8e26edc84a1a17a1 -address /var/run/docker/containerd/containerd.sock ├─ 1814 /usr/bin/containerd-shim-runc-v2 -namespace moby -id 657ed2d166be907825d627b88e1e2d2145feb13be8e34612757c14acff3c54b7 -address /var/run/docker/containerd/containerd.sock ├─ 1815 /usr/bin/containerd-shim-runc-v2 -namespace moby -id e8701b5b9260ce753ca45a62623fd612897dfdc226fd863a57ad0df014b964e6 -address /var/run/docker/containerd/containerd.sock ├─ 1816 /usr/bin/containerd-shim-runc-v2 -namespace moby -id f7c1e6c6e672c8be59c67598d1526217593fadf786d181f6461d214f12eabcb0 -address /var/run/docker/containerd/containerd.sock ├─3532314 /usr/bin/containerd-shim-runc-v2 -namespace moby -id 265090bb1930d612ee35ee89721f106dea829dfa29de26d049f29589c2bdde69 -address /var/run/docker/containerd/containerd.sock └─4092555 /usr/bin/containerd-shim-runc-v2 -namespace moby -id 0002bc11dbc7e5e44affeae75db12def472b7d77b63993f705fb77fd1298a2b7 -address /var/run/docker/containerd/containerd.sock ...具体内容如下:
root@oat-server:~# cat /lib/systemd/system/docker.service [Unit] Description=Docker Application Container Engine Documentation=http://docs.docker.com After=network.target docker.socket [Service] Type=notify EnvironmentFile=-/etc/sysconfig/docker WorkingDirectory=/usr/local/bin/ ExecStart=/usr/bin/dockerd \ --bip=172.17.0.1/16 \ $DOCKER_OPT_MTU \ -H unix:///var/run/docker.sock \ --selinux-enabled=false \ --log-opt max-size=1g \ --data-root=/docker \ --live-restore ExecReload=/bin/kill -s HUP $MAINPID # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=1048576 LimitNPROC=1048576 LimitCORE=infinity # Uncomment TasksMax if your systemd version supports it. # Only systemd 226 and above support this version. #TasksMax=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process Restart=on-failure [Install] WantedBy=multi-user.target将该 Service 配置文件中的
--bip=172.17.0.1/16修改为其它未使用的 CIDR 地址,比如172.31.0.1/16或者192.168.0.1/16。root@oat-server:~# vim /lib/systemd/system/docker.service ... ExecStart=/usr/bin/dockerd \ --bip=172.31.0.1/16 \ ...重启 Docker 服务来生效新的配置。
root@oat-server:~# systemctl reload docker.service root@oat-server:~# systemctl restart docker.service检查新的 IP 地址是否已经生效。
root@oat-server:~# ip -4 addr ... 3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default inet 172.31.0.1/16 brd 172.31.255.255 scope global docker0 valid_lft forever preferred_lft forever说明:重启 Docker 服务后,在修改 BIP 之前就已经创建的 OAT/MetaDB/OCP/ODC 等容器都还可以正常启动起来,不需要重建。
备注
如果 Docker 服务的 Service 配置文件中未指定 BIP 地址,也可以手动编译 Docker 服务默认的配置文件
/etc/docker/daemon.json来配置 BIP。root@oat-server:~# cat /etc/docker/daemon.json { "bip": "172.31.0.1/16" }注意:不要同时在 Service 配置文件和
/etc/docker/daemon.json配置文件中都指定 BIP 地址,否则启动 Docker 服务会遇到报错。unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives are specified both as a flag and in the configuration file: bip: (from flag: 172.17.0.1/16, from file: 192.168.0.1/16)推荐使用的 Docker BIP 地址范围如下(推荐私有网段)。
10.0.0.0/8(10.0.0.0 到 10.255.255.255)。172.16.0.0/12(172.16.0.0 到 172.31.255.255)。192.168.0.0/16(192.168.0.0 到 192.168.255.255)。
选择原则:避免与主机网络或现有子网冲突(如虚拟机、局域网)。
适用版本
OAT V4.1.0 及更高版本。
Docker 所有版本。