背景: harbor 默认启动会随机创建 172 网段的ip地址,跟集群规划的网段冲突
Harbor 网段修改步骤
0. 原来Harbor占用的网段
# 网桥名:harbor_harbor
[root@gpunode2 test]# docker network ls
NETWORK ID NAME DRIVER SCOPE
da8684ecc4b6 harbor_harbor bridge local
# 查看路由表
[root@gpunode2 test]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.21.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-da8684ecc4b6
# 查看网桥内部信息
docker inspect da8684ecc4b6
# 确认到Harbor占用的网段是172.21.0.0,和公司规划冲突
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-B4zFPkVD-1657849708271)(https://cdn.jsdelivr.net/gh/Fly0905/note-picture@main/imag/202207141603387.png)]
1、停止harbor
#停止harbor
docker-compose -f /opt/harbor/docker-compose.yml down
[root@gpunode2 harbor]# docker-compose -f /opt/harbor/docker-compose.yml down
Stopping harbor-jobservice ... done
Stopping nginx ... done
Stopping harbor-core ... done
Stopping harbor-db ... done
Stopping registry ... done
Stopping registryctl ... done
Stopping redis ... done
Stopping harbor-portal ... done
Stopping harbor-log ... done
Removing harbor-jobservice ... done
Removing nginx ... done
Removing harbor-core ... done
Removing harbor-db ... done
Removing registry ... done
Removing registryctl ... done
Removing redis ... done
Removing harbor-portal ... done
Removing harbor-log ... done
Removing network harbor_harbor
# 查看网桥,确认harbor_harbor是否已经删掉
docker network ls
# 如果没有,使用以下命令删除网桥
# docker network remove [NETWORK ID]
2、创建Harbor新的网桥
# 创建Harbor新的网桥
docker network create --driver=bridge --subnet=172.252.0.1/16 harbor
# 验证网桥信息
[root@gpunode2 harbor]# docker network ls
NETWORK ID NAME DRIVER SCOPE
e0a7e55534db harbor bridge local
[root@gpunode2 harbor]# route -n | grep e0a7e55534db
172.252.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-e0a7e55534db
3、修改compose配置
# 2. 修改docker-compose.yml 把最下面network false 改成true
networks:
harbor:
external: true
4、重新启动
# 重新启动
docker-compose -f /opt/harbor/docker-compose.yml up -d --force-recreate
- 1
- 2
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3fOraodQ-1657849708272)(https://cdn.jsdelivr.net/gh/Fly0905/note-picture@main/imag/202207141659623.png)]
注意
1. 启动方式
这种方式重启后,会使用新的网桥
但是使用.prepre
命令重新生成配置文件后,或者./install.sh
命令重装后,还是会创建harbor_harbor
随机网桥,可能会冲突
所以,在使用.prepre
命令或者./install.sh
命令后,记得修改docker-compose.yml
把最下面network false
改成true
2. 使用非172网段
如果使用非172网段,在步骤2:创建Harbor新的网桥
,还需要修改/etc/docker/daemon.json
中的bip
因为doker默认使用的也是172网段,所以harbor指定的也是172网段,就不需要额外修改docker配置,只需要修改harbor配置就好了
#修改docker 网络地址
$ cat /etc/docker/daemon.json
{
// 修改bip--network bridge IP
"bip":"172.254.0.1/16"
}
# 重启docker
systemctl daemon-reload
systemctl start docker
参考链接
https://docs.docker.com/engine/reference/commandline/dockerd/#/linux-configuration-file
https://goharbor.io/docs/2.0.0/install-config/run-installer-script/
ne/reference/commandline/dockerd/#/linux-configuration-file
https://goharbor.io/docs/2.0.0/install-config/run-installer-script/
https://docs.docker.com/compose/compose-file/