How to delete untagged images from AWS ECR Container Registry

前端 未结 4 1450
礼貌的吻别
礼貌的吻别 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:12

    Setting a Lifecycle policy is definitely the best way of managing this. That being said - if you do have a bunch of images that you want to delete keep in mind that the max for batch-delete-images is 100. So you need to do this is for the number of untagged images is greater than 100:

    IMAGES_TO_DELETE=$( aws ecr list-images --repository-name $ECR_REPO --filter "tagStatus=UNTAGGED" --query 'imageIds[0:100]' --output json )
    echo $IMAGES_TO_DELETE | jq length # Gets the number of results
    aws ecr batch-delete-image --repository-name $ECR_REPO --image-ids "$IMAGES_TO_DELETE" --profile qa || true
    

提交回复
热议问题