簡介:
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圖形界面中刪除不需要的鏡像
圖2:02-停止Harbor服務,執行垃圾回收命令
2、數人雲CTO肖總微信公號的文章:
圖3:老肖說兩句截圖
圖4:數人雲CTO肖總-微信公眾號-老肖說兩句
參考鏈接:
Harbor用戶指南
https://github.com/vmware/harbor/blob/master/docs/user_guide.md
刪除容器鏡像倉庫中的容器鏡像到底有多難?
Garbage collection
https://github.com/docker/docker.github.io/blob/master/registry/garbage-collection.md