Harbor私有仓库中如何彻底删除镜像释放存储空间?

2022-11-21 20:17:22 浏览数 (1)

简介:

Harbor私有仓库运行一段时间后,仓库中存有大量镜像,会占用太多的存储空间。直接通过Harbor界面删除相关镜像,并不会自动删除存储中的文件和镜像。需要停止Harbor服务,执行垃圾回收命令,进行存储空间清理和回收。

相关资料:

1、Harbor用户手册中的相关说明:

Next, delete the actual files of the repository using the registry’s garbage collection(GC). Make sure that no one is pushing images or Harbor is not running at all before you perform a GC. If someone were pushing an image while GC is running, there is a risk that the image’s layers will be mistakenly deleted which results in a corrupted image. So before running GC, a preferred approach is to stop Harbor first.

Run the below commands on the host which Harbor is deployed on to preview what files/images will be affected:

#要启用垃圾回收(GC),首先要关闭Harbor服务,然后再执行清理命令

#停止Harbor相关服务

代码语言:javascript复制
$ docker-compose stop

#使用–dry-run参数运行容器,预览运行效果,但不删除任何数据

$ docker run -it --name gc --rm --volumes-from registry vmware/registry:2.6.2-photon garbage-collect --dry-run /etc/registry/config.yml

#NOTE: The above option “–dry-run” will print the progress without removing any data.

Verify the result of the above test, then use the below commands to perform garbage collection and restart Harbor.

#不使用–dry-run参数,将删除相关的文件和镜像,

代码语言:javascript复制
$ docker run -it --name gc --rm --volumes-from registry vmware/registry:2.6.2-photon garbage-collect  /etc/registry/config.yml

#重新启动Harbor相关服务

$ docker-compose start

图1:01-先在Harbor UI图形界面中删除不需要的镜像

图2:02-停止Harbor服务,执行垃圾回收命令

0 人点赞