【nexus】CentOS7.x上nexus docker镜像仓库镜像的查询和删除

一、实验背景


【nexus】用nexus3.5搭建docker私有仓库

https://www.jianshu.com/p/7a7db54a538f

【nexus】用nexus3.x 官方镜像搭建docker私有镜像仓库

https://www.jianshu.com/p/86e573f18df3


现在许多团队使用 Nexus 来管理 Docker 镜像,版本不断迭代,镜像仓库占用的磁盘空间也越来越大。

Nexus 的控制台并未提供批量操作镜像功能,清理镜像十分不便,只能通过相关api来完成指定镜像的批量删除操作。

镜像内容是存储在一层虚拟文件系统(VFS)之上,由多个文件块(Blobs)描述清单文件(Manifests) 标签文件(tags)组成,因为镜像设计是多层的,这些文件会互相依赖,在没有确认文件块(Blob)是否被其他镜像使用的情况下,直接删除会让仓库不完整,所以一般的做法是只做删除标记,而不是真删除,通过垃圾回收机制来遍历当前仓库的有向关系图(DAG),然后在删除没有被引用的文件块。


关于镜像的批量删除,官方只提供方法思路,没有提供具体实现:


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-


二、实验环境

操作系统: CentOS7.5 Minimal

nexuserver: 192.168.1.105

nexusClient: 192.168.1.104


在nexusServer服务上

# docker ps -a

# systemctl status nexus

# cat   /etc/systemd/system/nexus.service

# ss -tan

浏览器访问:http://192.168.1.105:8081

admin/admin123

创建一个镜像仓库,仓库名为test ,端口为2019,协议为http

the URL used to access this repository

http://192.168.1.105:8081/repository/test

在nexusClient服务上

# cat  /usr/lib/systemd/system/docker.service 

# docker login 192.168.1.105:2019 -u admin -p admin123

# cat /root/.docker/config.json


三、镜像拉取推送、搜索、删除和垃圾回收


在nexusClient服务器上

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


浏览器访问:http://192.168.1.105:8081

创建两个Nexus Task 用于清理物理空间

查看帮助信息

# sh cleanNexus.sh -h

查询镜像

# sh cleanNexus.sh -q

删除指定版本镜像

# sh cleanNexus.sh  -d  busybox:1.0.1-RC1

批量删除指定版本镜像

# sh cleanNexus.sh -d  `cat imageList.txt`


四、参考


Linux上 强大的 JSON 数据命令行工具 jq安装使用

https://www.jianshu.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 磁盘空间怎么清理?

https://www.zhezhier.com/view/22958552


nexus3-cli

https://pypi.org/project/nexus3-cli


清理 Nexus 中无用的 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


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

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

你可能感兴趣的:(【nexus】CentOS7.x上nexus docker镜像仓库镜像的查询和删除)