3

I have an existing image inside an ECR repo with the tag "780" and I wanted to make a copy of it inside the same repo with the tag "781". I tried executing the below commands which I found from here but that gives a new tag to the same image when given the same repo.

docker login REPO
docker pull REPO/IMAGE:TAG
docker tag REPO/IMAGE:TAG REPO/IMAGE:NEWTAG
docker push REPO/IMAGE:NEWTAG

Is there an API or utility (preferably in python) or any other way using which this can be achieved?

Jay Shah
  • 41
  • 4

1 Answers1

2

It's not possible to have two Docker images in the same repo with the same SHA256 hash. The Docker repository is saving space by detecting that they are the same image, so it is simply adding the tags to the image that already exists in the repo. This is working as intended.

Mark B
  • 183,023
  • 24
  • 297
  • 295
  • That makes sense but I have a scenario where I want to use the already uploaded image as a base and then do changes and store it as a new image (with a different tag) without impacting the already existed image. So, Is there any way to achieve this? – Jay Shah Jul 14 '21 at 16:13
  • What makes you think that workflow you just described would somehow impact the already existing image? Hint: it would not. – Mark B Jul 14 '21 at 16:39
  • It will impact because currently if I try to do this in the same repository, it assigns a new tag to the same image. So, no matter from which tag we fetch it will update the same image whereas I want to isolate the two images from each other once copied. – Jay Shah Jul 14 '21 at 16:46
  • If you actually make a new image, with some changes from the existing base image, and then push that to the repository, it will show up as a new image, not simply a tag on the old image. You are seeing the current behavior because you are not pushing any changes at all, you are simply pushing the same image again that already exists in the repository. – Mark B Jul 14 '21 at 16:58