How to delete untagged images from AWS ECR Container Registry

前端 未结 4 1454
礼貌的吻别
礼貌的吻别 2020-12-16 12:34

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.

So if i docker

4条回答
  •  情话喂你
    2020-12-16 13:17

    I actually forged a one line solution using 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
    

    What it's doing is:

    • get all repositories
    • for each repository give me all images with tagStatus=UNTAGGED
    • for each image+repo issue a batch-delete-image

提交回复
热议问题