With the popularity of distributed and large-scale systems, there are more and more adoptions of cloud services. One of the most popular container in the market is Docker and one of the most popular cloud service provider is AWS. From development perspective, there is frequent need to push local docker image to remote ECR for debugging or testing purpose.
Normally when a code change is done and the committed change would go through a series of process like code review, push to remote repo, merge to master, trigger CI/CD pipeline and then get docker image generated and pushed to ECR, thereafter the image can be deployed on different systems.
However, during local development, sometimes one may wanna to deploy some debugging version of docker image to a distributed system hosted in some systems like AWS EKS to save the effort of going through above processes. In this post, some steps would be shown on how this can be achieved.
Before the image can be pushed to remote ECR, you first need to have aws cli installed so that you can login to remote ECR locally.
Now login to the ECR, can run below command:
aws ecr get-login-password --region ap-southeast-1 --profile [profile] | docker login --username AWS --password-stdin [ecr-host]
This command will first fetch the ECR login password for the specified profile and region and use it to do docker login. The parameters for docker login is the username, password and the ECR host.
Next step is the image to be pushed needs to be tagged, the command to tag the image
docker tag [image-id] [tag-name] // normally the tage name follows [ecr-host]/[ecr-repo];[tag-name[ format
Now comes the last step which is to run docker push
command.
docker push [tag-name]
After this step, the image should have been existing in remote ECR, you can login to AWS console to check the image.
If you want to pull an image from remote ECR, can just run
docker pull [tag-name]
Happy clouding.