Harbor磁盘爆满,执行垃圾回收清理镜像
#!/bin/bash set -e set -u # check disk df -h | grep data # stop harbor docker-compose -f /opt/harbor/docker-compose.yml down # setting harbor mv /opt/harbor/docker-compose.yml /opt/harbor/docker-compose.yml.common mv /opt/harbor/docker-compose.yml.clear /opt/harbor/docker-compose.yml mv /opt/harbor/common/config/registry/config.yml /opt/harbor/common/config/registry/config.yml.common mv /opt/harbor/common/config/registry/config.yml.clear /opt/harbor/common/config/registry/config.yml # start harbor docker-compose -f /opt/harbor/docker-compose.yml up -d # waiting healthy while [[ ! $(docker ps | grep -w healthy) ]] do echo "waiting healthy, sleep 3s..." sleep 3 done # clear docker run --network="host" -it -v /data/registry:/registry -e REGISTRY_URL=http://127.0.0.1:5000 mortensrasmussen/docker-registry-manifest-cleanup:1.1.2beta docker run -it --name gc --rm --volumes-from registry vmware/registry-photon:v2.6.2-v1.4.0 garbage-collect /etc/registry/config.yml # stop harbor docker-compose -f /opt/harbor/docker-compose.yml down # restore harbor mv /opt/harbor/docker-compose.yml /opt/harbor/docker-compose.yml.clear mv /opt/harbor/docker-compose.yml.common /opt/harbor/docker-compose.yml mv /opt/harbor/common/config/registry/config.yml /opt/harbor/common/config/registry/config.yml.clear mv /opt/harbor/common/config/registry/config.yml.common /opt/harbor/common/config/registry/config.yml # start harbor docker-compose -f /opt/harbor/docker-compose.yml up -d # waiting healthy while [[ ! $(docker ps | grep -w healthy) ]] do echo "waiting healthy, sleep 3s..." sleep 3 done # check disk df -h | grep data
1. 我的Harbor是安装在/opt/harbor目录下,所以建立脚本的时候注意按照自己的部署环境进行调整
2. 可以考虑放在cron定时任务中:0 0 * * * /opt/harbor/clean.sh,“/opt/harbor/clean.sh”即为刚刚建立的脚本,每天凌晨0点开始执行
备注:
/opt/harbor/docker-compose.yml.clear在原本的docker-compose.yml中增加了(加粗部分):
registry:
image: goharbor/registry-photon:v2.7.1-patch-2819-2553-v1.9.3
container_name: registry
(省略部分代码...)
ports:
- 127.0.0.1:5000:5000
(省略部分代码...)
/opt/harbor/common/config/registry/config.yml.clear在原本的config.yml中注释掉了(加粗部分):
http:
addr: :5000
secret: placeholder
debug:
addr: localhost:5001
#auth:
# token:
# issuer: harbor-token-issuer
# realm: http://registry.bocloud.com.cn/service/token
# rootcertbundle: /etc/registry/root.crt
# service: harbor-registry
validation:
disabled: true
(省略部分代码...)