https://blog.csdn.net/weixin_50902636/article/details/135317982

删除不掉镜像
docker image inspect --format=‘{{.RepoTags}} {{.Id}} {{.Parent}}’ $(docker image ls -q --filter since=5a64b7c87a1a)

自动清理镜像脚本

####自动清理脚本,若是harbor用的https,则将脚本中http改为https####

# yum install jq -y
jq:主要是用于shell与json结合,实现将数据输出为json,便于处理
# cat hub_image_clean.sh

#!/bin/bash
set -e
HARBOR_URL=192.168.0.58
HARBOR_PASSWD=Harbor12345
OLD_VERSION_NUM=4

function get_repos_list(){
  repos_list=$(curl -s -k -u admin:${HARBOR_PASSWD} http://${HARBOR_URL}/api/projects?page=1&page_size=50)
  mkdir -p $PWD/reposList
  echo "${repos_list}" | jq '.[]' | jq -r '.project_id' > $PWD/reposList/reposList.txt
}
function get_images_list(){
  mkdir -p $PWD/imagesList
  for repo in $(cat $PWD/reposList/reposList.txt);do
    images_list=$(curl -s -k -u admin:${HARBOR_PASSWD} http://${HARBOR_URL}/api/repositories?project_id=${repo})
    echo "${images_list}" | jq '.[]' | jq -r '.name' > $PWD/imagesList/${repo}.txt
  done
}
function delete_images(){
  #### get html
  htmlinfo=$(curl -s -k -u admin:${HARBOR_PASSWD} http://${HARBOR_URL}/api/repositories/$1/tags)
  #### images num
  num=$(echo "${htmlinfo}" | jq "length - ${OLD_VERSION_NUM}")
  if [[ "${num}" -le "0" ]]; then
    echo "$1 has no need of cleanup!!!"
    return
  fi
  #### get images_tag
# for index in $(seq 0 ${num}); do
  for index in $(seq 1 ${num}); do
#   tag=$(echo "${htmlinfo}" | jq ".[${index}]" | jq -r '.name')
#
    echo "${htmlinfo}" | jq -r '.[].name'|sort -n >tag.txt
    tag=`cat tag.txt |head -n $index |tail -n 1`
#
    echo "images=$1 ************************** tag= ${tag}"
    curl -s -k -u admin:${HARBOR_PASSWD} -X DELETE http://${HARBOR_URL}/api/repositories/$1/tags/${tag}
  done
}
function clean_registry(){
  image_name=$(docker ps | grep registry | grep photon | awk -F " " '{print $2}')
  docker run -it --name gc --rm --volumes-from registry ${image_name} garbage-collect  /etc/registry/config.yml
}
function entrance(){
  serverip=`ip addr|grep inet|grep 192.168|grep -v inet6|awk '{print $2}'|cut -d/ -f1`
  if [[ "$serverip" != "${HARBOR_URL}" ]]; then
    echo "harbor is not running in the machine!!!"
    exit 1
  fi
  get_repos_list
  get_images_list
  for repo in $(cat $PWD/reposList/reposList.txt);do
    for images in $(cat $PWD/imagesList/${repo}.txt); do
      delete_images ${images}
    done
  done
  clean_registry
}
entrance

参考链接:参考链接中脚本没法实现,有点问题,略做修改
https://www.cnblogs.com/breezey/p/10615231.html

GitHub 加速计划 / ha / harbor
23.24 K
4.67 K
下载
Harbor 是一个开源的容器镜像仓库,用于存储和管理 Docker 镜像和其他容器镜像。 * 容器镜像仓库、存储和管理 Docker 镜像和其他容器镜像 * 有什么特点:支持多种镜像格式、易于使用、安全性和访问控制
最近提交(Master分支:1 个月前 )
c5d26723 chore(deps): bump github.com/go-openapi/runtime in /src Bumps [github.com/go-openapi/runtime](https://github.com/go-openapi/runtime) from 0.26.2 to 0.28.0. - [Release notes](https://github.com/go-openapi/runtime/releases) - [Commits](https://github.com/go-openapi/runtime/compare/v0.26.2...v0.28.0) --- updated-dependencies: - dependency-name: github.com/go-openapi/runtime dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: miner <yminer@vmware.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Shengwen YU <yshengwen@vmware.com> Co-authored-by: miner <yminer@vmware.com> 14 天前
76624373 chore(deps): bump github.com/coreos/go-oidc/v3 in /src Bumps [github.com/coreos/go-oidc/v3](https://github.com/coreos/go-oidc) from 3.10.0 to 3.11.0. - [Release notes](https://github.com/coreos/go-oidc/releases) - [Commits](https://github.com/coreos/go-oidc/compare/v3.10.0...v3.11.0) --- updated-dependencies: - dependency-name: github.com/coreos/go-oidc/v3 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Shengwen YU <yshengwen@vmware.com> Co-authored-by: miner <yminer@vmware.com> 14 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐