Push docker image to remote AWS ECR

Summary

Developers frequently need to push local Docker images directly to AWS ECR for debugging or testing purposes, bypassing typical CI/CD workflows. The process begins by ensuring the AWS CLI is installed for authentication. Users then log in to ECR by piping the output of `aws ecr get-login-password` to `docker login` with the appropriate region and profile. Next, the local Docker image must be tagged using `docker tag`, following the ECR host and repository naming convention. The final step involves pushing the newly tagged image to the remote ECR repository with the `docker push` command.

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.

CLOUD DOCKER AWS AWS ECR

  RELATED

  COMMENTS

0

No comment for this article.