DEV Community


Posted on

Docker cross repository push

I just found 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

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

In, 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

Try to push

docker push

And ...

The push refers to repository []
tag does not exist:

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

Push away

Finally push the image and you are done.

docker push

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!

Discussion (0)