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点开始执行

Harbor磁盘爆满,执行垃圾回收清理镜像

上一篇:关于 QA 和自动化测试


下一篇:List集合