首页 > 其他 > 详细

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

时间:2021-07-26 22:27:56      阅读:41      评论:0      收藏:0      [点我收藏+]
#!/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磁盘爆满,执行垃圾回收清理镜像

原文:https://www.cnblogs.com/LOVE0612/p/15063425.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!