目录

Docker 修改内置 bridge ip 不生效, 原因及解决办法

目录

文章简介: docker 内置 bridge 的 ip 修改方法

Configure the default bridge network

docker daemon 的配置文件 /etc/docker/daemon.json 提供了自定义 docker builtin bridge 配置项.

1
2
3
4
5
6
7
8
9
# 修改 daemon.json 中 "bip"
{
    ....
    "bip: "100.100.1.1/24", # bip: 修改 builtin bridge 的 ip
	"default-address-pools":[{"base":"100.100.0.0/16","size":24}}
    ...
}

docker stop $(docker ps -qa) && systemctl restart docker && docker start $(docker ps -qa)

注意:

docker 如果已经有容器在运行,bip 的配置是不会生效。配置添加 {"debug": true} 后会有如下日志:

1
2
3
4
Jun 11 18:31:45 hostname dockerd[323728]: time="2022-06-11T18:31:45.251000544+08:00" level=debug msg="RequestPool(LocalDefault, 172.17.0.0/16, , map[], false)"
Jun 11 18:31:45 hostname dockerd[323728]: time="2022-06-22T18:31:45.251092001+08:00" level=debug msg="RequestAddress(LocalDefault/172.17.0.0/16, 172.17.0.1, map[RequestAddressType:com.docker.network.gateway])"
Jun 11 18:31:45 hostname dockerd[323728]: time="2022-06-11T18:31:45.251140234+08:00" level=debug msg="Request address PoolID:172.17.0.0/16 App: ipam/default/data, ID: LocalDefault/172.17.0.0/16, DBIndex: 0x0, Bits: 65536, Unselected: 65534, Sequence: (0x80000000, 1)->(0x0, 2046)->(0x1, 1)->end Curr:0 Serial:false PrefAddress:172.17.0.1 "
Jun 11 18:31:45 hostname dockerd[323728]: time="2022-06-11T18:31:45.272456556+08:00" level=info msg="There are old running containers, the network config will not take affect"

解决方法是先将所有启动的容器 stop,然后重启 docker 配置生效后,start 容器