MillerC
MillerC

Reputation: 731

Docker Push Adding Tags instead of Images

I have a private AWS ECR repository where I am pushing images.

I'm running the following commands to push images,

1. docker build -t $REPOSITORY_URL:develop -f ./docker/root/dockerfile .
2. docker push $REPOSITORY_URL:develop

This works and I can see a new image in my repository with the right image URI and Tag of develop.

However, when I try to add a new image with a different tag by using

1. docker build -t $REPOSITORY_URL:release -f ./docker/root/dockerfile .
2. docker push $REPOSITORY_URL:release

In my ECR repositoy I don't see a new image but I see my original image with two tags. The original develop tag and now the release tag.

I would expect since I am defining the $REPOSITORY_URL:release tag, as release, that when I run docker push $REPOSITORY_URL:release it would push my new image with a new tag, and I would be able to see two images in my ECR repository.

Currently the images are identical for testing purposes. Which I think is what is causing this problem. If I run the above commands with a different image it works as expected.

Is there a way to prevent this from happening? For example in production if I had to have identical images used my different tags, they would be able to push and work as expected?

Upvotes: 0

Views: 4047

Answers (1)

Adiii
Adiii

Reputation: 59896

If the image is same and you just push with different tag then ECR will check manifest will show it under against the same tag.

enter image description here In short, if image digest will same, ECR will consider it the same with a different tag.

enter image description here

So as your image is the same I will suggest using retagging image.

Retagging an Image

With Docker Image Manifest V2 Schema 2 images, you can use the --image-tag option of the put-image command to retag an existing image. You can retag without pulling or pushing the image with Docker. For larger images, this process saves a considerable amount of network bandwidth and time required to retag an image.

Also, there is interesting feature of ECR.

Image Tag Mutability

You can configure a repository to be immutable to prevent image tags from being overwritten. Once the repository is configured for immutable tags, an ImageTagAlreadyExistsException error will be returned if you attempt to push an image with a tag that already exists in the repository.

image-tag-mutability

Upvotes: 3

Related Questions