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

猜你喜欢

转载自blog.csdn.net/red_sky_blue/article/details/126501314
今日推荐