Home > Net >  when tagging and pushing docker image to AWS ECR it creates an untagged version
when tagging and pushing docker image to AWS ECR it creates an untagged version

Time:07-13

enter image description hereI'm using bitbucket pipelines to build and psuh my docker image to Amazon ECR. I notice that it overrides the existing image in the repository which is what I want but somehow there is now an additional (untagged) image in the repo. How do I ensure that there is only one image?

I'm using the following in my script:

docker build . -t 211012356392.dkr.ecr.us-west-2.amazonaws.com/myorg/myapp:latest_$BITBUCKET_BRANCH       
docker push 211012356392.dkr.ecr.us-west-2.amazonaws.com/myorg/myapp:latest_$BITBUCKET_BRANCH
        

CodePudding user response:

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.

That's why it seems like it creates an untagged image. In your snippet you can see this by looking at the timestamps. There is a time difference

You can delete all untagged images using the following commands:

IMAGES_TO_DELETE=$( aws ecr list-images --region $ECR_REGION --repository-name $ECR_REPO --filter "tagStatus=UNTAGGED" --query 'imageIds[*]' --output json )

aws ecr batch-delete-image --region $ECR_REGION --repository-name $ECR_REPO --image-ids "$IMAGES_TO_DELETE" || true
  • Related