我们在使用Nexus做maven、docker的私有仓库。由于项目迭代过多,ci时推送的镜像过多,导致nexus占用的磁盘空间较大。此文档用于记录清理无用docker镜像的过程。使用清理 Nexus 中 Docker 镜像的小工具 — nexus-cli。
下载脚本
1
2
3
|
$ wget https://s3.eu-west-2.amazonaws.com/nexus-cli/1.0.0-beta/linux/nexus-cli
$ chmod +x nexus-cli
$ mv nexus-cli /usr/local/bin/
|
配置待清理的库
1
2
3
4
5
|
$ nexus-cli configure
Enter Nexus Host: http://172.16.xx.xx:30881
Enter Nexus Repository Name: docker-repo-hosted
Enter Nexus Username: admin
Enter Nexus Password: xxxxxx
|
列出所有镜像
nexus-cli的相关命令参考官方某博客
1
2
3
4
5
6
7
8
9
10
|
$ nexus-cli image ls
......
bl-trex-job
bl-trex-web
bl-trex-web-dev
bl-trex-web-test
bl-trex-websocket
bl-websocket
ladeit-web-dev
......
|
清理镜像
1
2
3
4
5
6
7
8
9
10
|
# 清理镜像的tag 保留最新的15个tag
$ nexus-cli image delete --name ladeit-web-dev --keep 15
ladeit-web-dev:0.0.1 image will be deleted ...
ladeit-web-dev:0.0.1 has been successful deleted
ladeit-web-dev:5597 image will be deleted ...
ladeit-web-dev:5597 has been successful deleted
ladeit-web-dev:5601 image will be deleted ...
ladeit-web-dev:5601 has been successful deleted
ladeit-web-dev:5604 image will be deleted ...
ladeit-web-dev:5604 has been successful deleted
|
清理磁盘空间
上面的删除操作不会清理真实的磁盘空间,需要创建两个Nexus Task来清理磁盘空间
分别创建Purge unused docker manifests and images, Compact blob store。(我这里已经创建好了)
创建好之后先运行Purge unused docker manifests and images,再运行 Compact blob store。执行完之后再去看磁盘空间就会发现已经腾出来很大的空间了。
参考链接
nexus-cli
Author
dylan
LastMod
2020-06-23
License
如需转载请注明文章作者和出处。谢谢!