Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker force overwrite last tag and pushing on AWS ECR

I'm pushing my images to AWS ECR via docker push ... command. The image is tagged with a specific version.

When I actually push two different images with the same tag, this results in two images on the AWS ECR registry, one which become untagged.

0.0.1 sha256:572219f8764b21e5a045bcc1c5eab399e2bc2370a37b23cb1ca9298ea39e233a 138.33 MB
      sha256:60d161db0b9cb1345cf7c3e6119b8eba7114bc2dfc44c0b3ed02454803f6ef76 138.21MB

The problem this is causing is that if I continue to push more images with the same tag, the total size of the repository keeps increasing.

What I would like is to "overwrite" the existing tag when pushing an image. Which means that two different sha256 digest with the same tag would result in a single image on the registry (of course multiple when tag version changes).

Is it possible to do so? I would like to avoid an "untagged" pruning technique if possible. For now, my publish script delete the previous same tag if it exists but I feel this should be handled by AWS ECR or docker push directly.

like image 660
Matt Avatar asked Jul 17 '17 04:07

Matt


1 Answers

Unfortunately this is not possible. Here is what you can do:

  1. Use 2 different tags for the images that you want to overwrite. I would recommend a tag with the version and another tag with a known prefix and something guaranteed unique e.g. 1.1.1 and SNAPSHOT-hash. The next time you push an image with the same version, the tag 1.1.1 will be removed from the old image and added to the new image. However the SNAPSHOT-* tags will remain in all images.
  2. Configure a lifecycle policy where images starting from SNAPSHOT- will expire after an image count of more than x. This way, old images will automatically expire.
like image 103
kopelitsa Avatar answered Oct 12 '22 14:10

kopelitsa