一沛婴、實(shí)驗(yàn)背景
【nexus】用nexus3.5搭建docker私有倉(cāng)庫(kù)
http://www.reibang.com/p/7a7db54a538f
【nexus】用nexus3.x 官方鏡像搭建docker私有鏡像倉(cāng)庫(kù)
http://www.reibang.com/p/86e573f18df3
現(xiàn)在許多團(tuán)隊(duì)使用 Nexus 來(lái)管理 Docker 鏡像荷腊,版本不斷迭代,鏡像倉(cāng)庫(kù)占用的磁盤(pán)空間也越來(lái)越大任洞。
Nexus 的控制臺(tái)并未提供批量操作鏡像功能,清理鏡像十分不便,只能通過(guò)相關(guān)api來(lái)完成指定鏡像的批量刪除操作氧苍。
鏡像內(nèi)容是存儲(chǔ)在一層虛擬文件系統(tǒng)(VFS)之上,由多個(gè)文件塊(Blobs)泛范、描述清單文件(Manifests)和 標(biāo)簽文件(tags)組成让虐,因?yàn)殓R像設(shè)計(jì)是多層的,這些文件會(huì)互相依賴(lài)罢荡,在沒(méi)有確認(rèn)文件塊(Blob)是否被其他鏡像使用的情況下赡突,直接刪除會(huì)讓倉(cāng)庫(kù)不完整对扶,所以一般的做法是只做刪除標(biāo)記,而不是真刪除惭缰,通過(guò)垃圾回收機(jī)制來(lái)遍歷當(dāng)前倉(cāng)庫(kù)的有向關(guān)系圖(DAG)浪南,然后在刪除沒(méi)有被引用的文件塊。
關(guān)于鏡像的批量刪除漱受,官方只提供方法思路络凿,沒(méi)有提供具體實(shí)現(xiàn):
How to delete docker images from Nexus Repository Manager
https://support.sonatype.com/hc/en-us/articles/360009696054-How-to-delete-docker-images-from-Nexus-Repository-Manager
What command line tools are available for Nexus?
https://support.sonatype.com/hc/en-us/articles/213465898-What-command-line-tools-are-available-for-Nexus-
二、實(shí)驗(yàn)環(huán)境
操作系統(tǒng): CentOS7.5 Minimal
nexuserver: 192.168.1.105
nexusClient: 192.168.1.104
在nexusServer服務(wù)上
# docker ps -a
# systemctl status nexus
# cat?? /etc/systemd/system/nexus.service
# ss -tan
瀏覽器訪問(wèn):http://192.168.1.105:8081
admin/admin123
創(chuàng)建一個(gè)鏡像倉(cāng)庫(kù)拜效,倉(cāng)庫(kù)名為test 喷众,端口為2019,協(xié)議為http
the URL used to access this repository
http://192.168.1.105:8081/repository/test
在nexusClient服務(wù)上
# cat??/usr/lib/systemd/system/docker.service?
# docker login 192.168.1.105:2019 -u admin -p admin123
# cat /root/.docker/config.json
三紧憾、鏡像拉取推送到千、搜索、刪除和垃圾回收
在nexusClient服務(wù)器上
shell腳本:https://github.com/IamMichael/nexusCleanUp.git
# yum? -y? install jq
腳本用到的api
nexus REST and Integration API
https://help.sonatype.com/repomanager3/rest-and-integration-api
http://192.168.1.105:8081/#admin/system/api
Docker Registry HTTP API V2
https://docs.docker.com/registry/spec/api/#deleting-an-image
瀏覽器訪問(wèn):http://192.168.1.105:8081
創(chuàng)建兩個(gè)Nexus Task 用于清理物理空間
查看幫助信息
# sh cleanNexus.sh -h
查詢(xún)鏡像
# sh cleanNexus.sh -q
刪除指定版本鏡像
# sh cleanNexus.sh? -d? busybox:1.0.1-RC1
批量刪除指定版本鏡像
# sh cleanNexus.sh -d? `cat imageList.txt`
四赴穗、參考
Linux上 強(qiáng)大的 JSON 數(shù)據(jù)命令行工具 jq安裝使用
http://www.reibang.com/p/fee92cf8be1c
How to delete docker images from Nexus Repository Manager?
https://support.sonatype.com/hc/en-us/articles/360009696054-How-to-delete-docker-images-from-Nexus-Repository-Manager
https://stackoverflow.com/questions/38837028/remove-docker-images-from-nexus-repository-manager-oss-3-0-1-01
Cleanup old Docker images from Nexus Repository
https://hackernoon.com/cleanup-old-docker-images-from-nexus-repository-617b1004dad8
https://www.blog.labouardy.com/cleanup-old-docker-images-from-nexus-repository/?spm=a2c4e.10696291.0.0.42ed19a4YN4lJx
nexus 磁盤(pán)空間怎么清理?
https://www.zhezhier.com/view/22958552
nexus3-cli
https://pypi.org/project/nexus3-cli
清理 Nexus 中無(wú)用的 Docker 鏡像
https://yq.aliyun.com/articles/666110
https://cloud.tencent.com/developer/article/1361709
Sonatype-Nexus Cleanup — Advanced level
https://tech.travelaudience.com/sonatype-nexus-cleanup-advanced-level-ea28692f2911
刪除容器鏡像倉(cāng)庫(kù)中的容器鏡像到底有多難憔四?
https://mp.weixin.qq.com/s?__biz=MzA4ODgwNTk1NQ==&mid=2649949694&idx=1&sn=eda4513942458714a1eb89aaa25c9954&chksm=882322d2bf54abc4cb4e5c37fe348e2849c14f3d7e2897a0d839a045d8789640a1b99ca26d44&mpshare=1&scene=2&srcid=0226hpbvbowRZphA0jkqkTlq&from=timeline#rd