linuxea:nexus3排序清理docker镜像列表

marksugar
2021-12-24 / 0 评论 / 1,008 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2021年12月24日,已超过345天没有更新,若内容或图片失效,请留言反馈。

nexus3的出现可以替代很多产品,nexus3整合了常用的功能,比如docker镜像仓库等。

一般我们在配置docker仓库的时候,在blob stores中创建的新的stores来存储镜像。这样方便管理

image-20211224222017526.png

早期的nexus-cli已经没有维护,nexus-cli删除的镜像并没有按照时间的顺序进行保留 。需要在13rentgen的仓库中下载修复版的,所以你需要下载最新的进行使用登录nexus下载最新的修复版本

https://github.com/13rentgen/nexus-cli/releases/tag/v1.1.0

这里演示用的是旧的版本

[root@nexus ]# ./nexus-cli --version
Nexus CLI version 1.0.0-beta

登录nexus

[root@nexus ~]# nexus-cli configure
Enter Nexus Host: http://127.0.0.1:38081
Enter Nexus Repository Name: docker-host
Enter Nexus Username: admin
Enter Nexus Password: yxt@..123!com

列出镜像

[root@nexus ~]# nexus-cli image ls

删除命令

nexus-cli image delete -name IMAGE_NAME -keep X,-keep X 表示保留几个tag

如果是单个删除,那么命令如下

nexus-cli image delete -name  dnotask1  -keep 10
nexus-cli image delete -name  outage2  -keep 10
nexus-cli image delete -name  1speed -keep 10
nexus-cli image delete -name  mongo2 -keep 10
nexus-cli image delete -name  mongo1 -keep 10

清理脚本

#!/bin/bash
# Copyright 2022 marksugar, personal
#           2022 linuxea.com
# Author: mark  <usertzc#163.com>
USER=admin
PASS="password"
REPO=docker-host
HOST="http://127.0.0.1:38081"
CLEAN_DISK_NAME=/data/


touchnet(){
    local recode=`curl  -o /dev/null  -s --connect-timeout 3 $1 -w %{http_code}`
    if [ "$recode" == "200" ]; then
       return 1
    fi
}
Create_CRE(){
  # protect file since it contains secrets
  touch ~/.credentials && chmod 600 ~/.credentials

  # update file using environment variables

  cat << _EOF > ~/.credentials
# Nexus Credentials
nexus_host = "${HOST}"
nexus_username = "${USER}"
nexus_password = "${PASS}"
nexus_repository = "${REPO}"
_EOF
}
touchnet ${HOST}
if [ `echo $?` == "1" ]; then    [ -f ~/.credentials ] || Create_CRE ;  else   echo "Cannot communicate with the ${HOST}";exit -1; fi

PATHS=yxt-vehicle
PATH_NAME="dnotask1 outage21speed mongo2 mongo1"
TAKE_NUM=10
type nexus-cli > /dev/null 2>&1 && echo " nexus-cli is ok" ||  { echo "error  nexus-cli is not install";exit -1 ;}
if [ `df -hT ${CLEAN_DISK_NAME} | tail -1| awk '{print $6}'| awk -F% '{print $1}'`  -gt 80 ];then
    for i in `echo ${PATH_NAME}`;do  echo -e "\033[34m $i Start cleaning, keep the last 10 \033[0m" && nexus-cli image delete -name ${PATHS}/${i} -keep ${TAKE_NUM} ;done
fi

清理完成后进行删除

Tasks --> create task --> delete unused manifests and images Task

image-20211122142423201.png

执行完就消失了

Tasks --> create task ---> compact blob store Task

image-20211122143334250.png

而后指定store清理Compact blob store

0

评论

博主关闭了当前页面的评论