DEV Community

Tathagata
Tathagata

Posted on

Docker cross repository push

header
I just found dev.to and immediately fell in love with the retro 🤣 look! Instead of putting in much thought, I started brain dumping - mainly about things that did not work on the first go. No effort has been made to be helpful - typos, errors, misinformation may lay ahead. Welcome to the Internet!

Problem: Need to push a docker image from one AWS account to another

ECR is the docker repository as a service provided by AWS. To have better separation of your environment, you would typically have a prod account and one or more non-prod accounts. Your CI pipeline would be running in your non-prod account allowing you to rapidly iterate and build new images. Once your testing cycle completes, you would want to promote this image to the production account. Below are the set of commands needed to promote your release candidate from non-prod to production.

Login to your docker registry of source account

aws ecr --profile dev --region us-east-1 get-login --no-include-email | bash
Enter fullscreen mode Exit fullscreen mode

Pretty straight forward. Make a cli call which returns the docker login command which is piped to execute in bash. dev is the aws profile for the account which contains the docker image.

CI produced docker image

docker pull 123456789012.dkr.ecr.us-east-1.amazonaws.com/img:aa567e02ae7477a6b022da30fa50137a252dd143
Enter fullscreen mode Exit fullscreen mode

In 123456789012.dkr.ecr.us-east-1.amazonaws.com, 123456789012 stands for the account number of aws account where our docker image lives.
Lets say you have done your testing and you are now satisfied to promote this to prod.

Switch repository and try to push

Login to prod

aws ecr --profile prod --region eu-west-1 get-login --no-include-email | bash
Enter fullscreen mode Exit fullscreen mode

Try to push

docker push 234567890121.dkr.ecr.us-east-1.amazonaws.com/img:ab77ad7b362d7552bc2c7a69f2650a5b50bcdcc1
Enter fullscreen mode Exit fullscreen mode

And ...

The push refers to repository [234567890121.dkr.ecr.us-east-1.amazonaws.com/img]
tag does not exist: 234567890121.dkr.ecr.us-east-1.amazonaws.com/img:aa567e02ae7477a6b022da30fa50137a252dd143
Enter fullscreen mode Exit fullscreen mode

Uh oh forgot to tag

This was not very obvious to me. But docker, awesome as it is, gives you the nice error message above telling exactly where things are going wrong. To push to the prod registry, you'll need to tag the image accordingly.

docker tag 123456789012.dkr.ecr.us-east-1.amazonaws.com/img:aa567e02ae7477a6b022da30fa50137a252dd143 234567890121.dkr.ecr.us-east-1.amazonaws.com/img:aa567e02ae7477a6b022da30fa50137a252dd143
Enter fullscreen mode Exit fullscreen mode

Push away

Finally push the image and you are done.

docker push 234567890121.dkr.ecr.us-east-1.amazonaws.com/img:ab77ad7b362d7552bc2c7a69f2650a5b50bcdcc1
Enter fullscreen mode Exit fullscreen mode

Congratulations, you have promoted the image!

Wait. What does the picture above got to do with this post?

Not a single thing. This is a picture I took at Siena. ❤️Italy, can't wait to go back!

Top comments (0)