Step by Step Guide
Amazon Elastic Container Registry (ECR) is a container image registry that we can use push Docker images to on AWS. Why use a Container Registry? It helps make it easy to manage your various images and separate projects. For example, when I first started working with Docker locally I didn’t realize how many images I had built. It was hard for me to track my images for different projects, I needed a central resource and ECR was my registry of choice as I worked with AWS frequently.
That brings me to my second reason to use ECR. There are different container registries that are available, but if you’re a big AWS user, ECR integrates directly with a lot of other services on the platform. Examples of this include providing custom images for your Lambda Function and building your own container for SageMaker Training and Inference. In this article we’ll take a quick look on how you can push an image to a repository on ECR.
NOTE: For those of you new to AWS, make sure you make an account at the following link if you want to follow along. This article will also assume basic familiarity with Docker, AWS, and using the AWS CLI.
Pull Docker Image Locally
To get started, make sure that you have Docker installed and running. From the AWS side make sure that you have the AWS CLI installed for us to work with services such as ECR.
For simplicity’s sake we won’t worry about building our own custom image, we can grab one of the existing images from the Docker Hub for this article.
You should be able to see the hello-world image if you run the following command.
Let’s now get this image pushed to ECR.
Creating ECR Repository
Before we can push our image we need to create an ECR repository. All of these interactions with ECR can be managed via the AWS CLI. To further understand setting up and configuring the CLI please reference this article.
Before creating the repository we need to login to our ECR registry, that can be done with the following command.
Make sure to provide the proper account ID if you run into an error saying “no auth credentials”, this will vary depending on the region that you are in.
After we’ve logged in we can create our repository with the “create repository” call.
Upon successful creation you should see your Repositories metadata reflected in the terminal, we can also confirm this in the Console.
Next up is taking our local image we have and pushing it to this hello-world repository that we have created.
Pushing Image to ECR
Before pushing our image we need to tag it to identify with our repository. The expected format is the following: aws_account_id.dkr.ecr.region.amazonaws.com/my-repository:tag
We can apply this format to your “hello-world” image by tagging it with the following command.
You can also verify that this image has been properly tagged by running another “docker images” command to list and search for the newly tagged image.
Now we can push this image to ECR with the following command.
We can verify the image exists in repo by checking the Console again.
Now that you have your image in the repository you can pull it, push multiple versions, just as you would with Docker locally. The main benefit here is you can organize and track all these different projects and images properly with the Registry.
Additional Resources & Conclusion
You can access all the ECR AWS CLI commands at the link above, there’s also CLI commands for other popular AWS services such as Lambda. Working with ECR is fairly simple when you have familiarity with Docker and the CLI. If you’re further interested in Docker with AWS, check out the other services that you run Docker on here.
I hope this article was a good primer on pushing your Docker images to ECR, you can reference the official documentation here. Feel free to check out the following list for other AWS content.
Step by Step Guide
Amazon Elastic Container Registry (ECR) is a container image registry that we can use push Docker images to on AWS. Why use a Container Registry? It helps make it easy to manage your various images and separate projects. For example, when I first started working with Docker locally I didn’t realize how many images I had built. It was hard for me to track my images for different projects, I needed a central resource and ECR was my registry of choice as I worked with AWS frequently.
That brings me to my second reason to use ECR. There are different container registries that are available, but if you’re a big AWS user, ECR integrates directly with a lot of other services on the platform. Examples of this include providing custom images for your Lambda Function and building your own container for SageMaker Training and Inference. In this article we’ll take a quick look on how you can push an image to a repository on ECR.
NOTE: For those of you new to AWS, make sure you make an account at the following link if you want to follow along. This article will also assume basic familiarity with Docker, AWS, and using the AWS CLI.
Pull Docker Image Locally
To get started, make sure that you have Docker installed and running. From the AWS side make sure that you have the AWS CLI installed for us to work with services such as ECR.
For simplicity’s sake we won’t worry about building our own custom image, we can grab one of the existing images from the Docker Hub for this article.
You should be able to see the hello-world image if you run the following command.
Let’s now get this image pushed to ECR.
Creating ECR Repository
Before we can push our image we need to create an ECR repository. All of these interactions with ECR can be managed via the AWS CLI. To further understand setting up and configuring the CLI please reference this article.
Before creating the repository we need to login to our ECR registry, that can be done with the following command.
Make sure to provide the proper account ID if you run into an error saying “no auth credentials”, this will vary depending on the region that you are in.
After we’ve logged in we can create our repository with the “create repository” call.
Upon successful creation you should see your Repositories metadata reflected in the terminal, we can also confirm this in the Console.
Next up is taking our local image we have and pushing it to this hello-world repository that we have created.
Pushing Image to ECR
Before pushing our image we need to tag it to identify with our repository. The expected format is the following: aws_account_id.dkr.ecr.region.amazonaws.com/my-repository:tag
We can apply this format to your “hello-world” image by tagging it with the following command.
You can also verify that this image has been properly tagged by running another “docker images” command to list and search for the newly tagged image.
Now we can push this image to ECR with the following command.
We can verify the image exists in repo by checking the Console again.
Now that you have your image in the repository you can pull it, push multiple versions, just as you would with Docker locally. The main benefit here is you can organize and track all these different projects and images properly with the Registry.
Additional Resources & Conclusion
You can access all the ECR AWS CLI commands at the link above, there’s also CLI commands for other popular AWS services such as Lambda. Working with ECR is fairly simple when you have familiarity with Docker and the CLI. If you’re further interested in Docker with AWS, check out the other services that you run Docker on here.
I hope this article was a good primer on pushing your Docker images to ECR, you can reference the official documentation here. Feel free to check out the following list for other AWS content.