Remove tag from image
You can delete a tag using command:
aws ecr batch-delete-image --repository-name <REPO NAME> --image-ids imageTag=<TAG NAME>
I you have only one tag and execute this command then it will remove the image. If you have multiple tags for the same image, specify one and only the tag is removed.
In case one needs to delete more tags, here is a an extension of the accepted answer:
ECR_REPO="my-repo-name"
# Create a file with the list of AWS ECR tags, with one tag per line
aws ecr list-images --repository-name $ECR_REPO --filter "tagStatus=TAGGED" \
--query "imageIds[*]" --output text \
| cut -f2 > ecr-image-tags-${ECR_REPO}.txt
# For each tag, delete the image on AWS ECR
cat ecr-image-tags-${ECR_REPO}.txt | xargs -I {} \
aws ecr batch-delete-image --repository-name ${ECR_REPO} --image-ids imageTag={} | cat
You can also replace cat
by grep -E PATTERN
in the last line if you want to selectively delete tagged images with a specific pattern.