Harbor 垃圾清理
[root@dev10 harbor]# pwd
/root/softwares/harbor
[root@dev10 harbor]#

1 编辑 /root/softwares/harbor/common/config/registry/config.yml 此文件在harbor安装目录下, 关闭的目的是为了禁止身份验证

version: 0.1
log:
  level: info
  fields:
    service: registry
storage:
  cache:
    layerinfo: redis
  filesystem:
    rootdirectory: /storage
  maintenance:
    uploadpurging:
      enabled: false
  delete:
    enabled: true
redis:
  addr: redis:6379
  password:
  db: 1
http:
  addr: :5000
  secret: placeholder
  debug:
    addr: localhost:5001

## 先禁止身份验证,GC后在改回来
#auth:
#  token:
#    issuer: harbor-token-issuer
#    realm: http://sinoeyes.io/service/token
#    rootcertbundle: /etc/registry/root.crt
#    service: harbor-registry
notifications:
  endpoints:
  - name: harbor
    disabled: false
    url: http://core:8080/service/notifications
    timeout: 3000ms
    threshold: 5
    backoff: 1s

2 修改 /root/softwares/harbor/docker-compose.yml 此文件在harbor安装目录下,修改此文件的目的是把registry port端口暴露出来

version: '2'
services:
......
  registry:
    image: goharbor/registry-photon:v2.6.2-v1.7.4
    ## 把registry port端口暴露出来,GC后在改回来
    ports:
      - 127.0.0.1:5000:5000
    container_name: registry
    restart: always
......

3 停止 harbor 并且 启动 harbor
注意: 不要使用 stop 停止,否则修改的配置文件不会生效

[root@dev10 harbor]# docker-compose down && docker-compose up -d

4 查看 Harbor 自带的 registry-photon 名称与版本

[root@dev10 harbor]# docker images | grep registry-photon
goharbor/registry-photon         v2.6.2-v1.7.4       f4743bd7b0d9        7 months ago        86.7MB
[root@dev10 harbor]#

5 清理已删除未使用的清单

[root@dev10 harbor]# docker run --network="host" -it -v /data/registry:/registry -e REGISTRY_URL=http://127.0.0.1:5000 mortensrasmussen/docker-registry-manifest-cleanup

6 清理已删除现在不再与清单关联的blob

[root@dev10 harbor]# docker run -it --name gc --rm --volumes-from registry goharbor/registry-photon:v2.6.2-v1.7.4 garbage-collect /etc/registry/config.yml

7 把步骤1和步骤2的配置修改回初始状态

8 在次执行第3步

转载 Harbor删除镜像后且GC清理后,磁盘空间没有释放的问题

分类: Docker

毛巳煜

高级软件开发全栈架构师

工信部备案号:辽ICP备17016257号-2