解决registry私有仓库空间清理问题
作者:楠奕
Docker Registry因历史镜像堆积导致磁盘空间不足,需定期清理,通过执行registry_garbage_collect.sh脚本及查看config.yml配置文件,可管理存储策略,释放占用空间
registry私有仓库空间清理
docker registry中堆积的历史镜像数量极多,磁盘空间告急,为此,有必要定期做镜像的清理,并释放镜像占用的存储空间。
查看脚本registry_garbage_collect.sh
# cat registry_garbage_collect.sh #!/bin/bash set -e #v2仓库镜像名称 dockerConfPath=/data/install/app/registry/configyml configFile=${dockerConfPath}/config.yml #修改仓库属性设置为只读 ansible registry192.168.246.10 -m shell -a "sed -i '14s/enabled: false/enabled: true/' ${configFile}" ansible registry192.168.246.11 -m shell -a "sed -i '14s/enabled: false/enabled: true/' ${configFile}" #重启仓库组件 ansible registry192.168.246.10 -m shell -a "docker restart pro-registry" ansible registry192.168.246.11 -m shell -a "docker restart pro-registry" #执行仓库垃圾回收 ansible registry192.168.246.10 -m shell -a "docker exec pro-registry registry garbage-collect /etc/docker/registry/config.yml" #修改仓库属性设置为可写 ansible registry192.168.246.10 -m shell -a "sed -i '14s/enabled: true/enabled: false/' ${configFile}" ansible registry192.168.246.11 -m shell -a "sed -i '14s/enabled: true/enabled: false/' ${configFile}" #重启仓库组件 ansible registry192.168.246.10 -m shell -a "docker restart pro-registry" ansible registry192.168.246.11 -m shell -a "docker restart pro-registry"
其中,246.10-11为仓库所在的主机
仓库名
pro-registry,即docker启动registry镜像时的镜像名
查看configyml文件
version: 0.1 log: fields: service: registry storage: cache: blobdescriptor: inmemory filesystem: rootdirectory: /var/lib/registry delete: enabled: true maintenance: readonly: enabled: false http: addr: :5000 headers: X-Content-Type-Options: [nosniff] health: storagedriver: enabled: true interval: 10s threshold: 3
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。