如何从AWS ECR容器注册表中删除未标记的图像 [英] How to delete untagged images from AWS ECR Container Registry

查看:250
本文介绍了如何从AWS ECR容器注册表中删除未标记的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将图像推送到Amazon ECR时,如果存储库中已存在标签,则旧图像将保留在注册表中,但处于未标记状态.

When pushing images to Amazon ECR, if the tag already exists within the repo the old image remains within the registry but goes in an untagged state.

因此,如果我第二次使用docker push image/haha:1.0.0(假设有所更改),则第一张图像将从AWS ECR取消标记.

So if i docker push image/haha:1.0.0 the second time i do this (provided that something changes) the first image gets untagged from AWS ECR.

有没有一种方法可以安全地清除未标记图像中的所有注册表?

Is there a way to safely clean up all the registries from untagged images?

推荐答案

我实际上是使用aws cli

aws ecr describe-repositories --output text | awk '{print $5}' | while read line; do  aws ecr list-images --repository-name $line --filter tagStatus=UNTAGGED --query 'imageIds[*]' --output text | while read imageId; do aws ecr batch-delete-image --repository-name $line --image-ids imageDigest=$imageId; done; done

它的作用是:

  • 获取所有存储库
  • 对于每个存储库,请给我所有带有tagStatus=UNTAGGED
  • 的图像
  • 为每张图片和存储库发布batch-delete-image
  • get all repositories
  • for each repository give me all images with tagStatus=UNTAGGED
  • for each image+repo issue a batch-delete-image

这篇关于如何从AWS ECR容器注册表中删除未标记的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆