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

简介:

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相关服务

$ 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参数,将删除相关的文件和镜像,

$ 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图形界面中删除不需要的镜像

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

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

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

2、数人云CTO肖总微信公号的文章:

图3:老肖说两句截图

03-老肖说两句截图

图4:数人云CTO肖总-微信公众号-老肖说两句

04-数人云CTO微信公众号-老肖说两句

参考链接:

Harbor用户指南

https://github.com/vmware/harbor/blob/master/docs/user_guide.md

删除容器镜像仓库中的容器镜像到底有多难?

http://mp.weixin.qq.com/s?__biz=MzA4ODgwNTk1NQ==&mid=2649949694&idx=1&sn=eda4513942458714a1eb89aaa25c9954&chksm=882322d2bf54abc4cb4e5c37fe348e2849c14f3d7e2897a0d839a045d8789640a1b99ca26d44&mpshare=1&scene=2&srcid=0226hpbvbowRZphA0jkqkTlq&from=timeline#rd

Garbage collection

https://github.com/docker/docker.github.io/blob/master/registry/garbage-collection.md

posted @ 2018-04-09 22:59  Docker猫猫  阅读(13598)  评论(1编辑  收藏  举报