Using Amazon Elastic Container Registry

Pablo Ezequiel Inchausti
5 min readJan 14, 2017

With Amazon Elastic Container Registry (ECR) you can manage your own docker images inside AWS, thats could be useful if you need to deal with private docker images and don’t want to use other popular public alternatives like Docker hub.

The service AWS ECR is included in the AWS free tier of AWS so we can use it in a very basic way, limited to 500 mb, at any costs while the free tier is available:

ECR Free Tier limited to 500 Mb

This is true that, when we are building docker images, 500 mb is very easy to exceed, so be careful to remove unused docker images.

The service ECR belongs to the “containers” group with ECS and EKS

AWS Containers Services: ECR, ECS and EKS

Let’s start to see how to use it:

Preconditions

Before we start, we need comply with some preconditions, that we could find detailed in the Official AWS ECR Documentation Page

  • An AWS account (free tier is Ok)
  • An IAM user with AdministratorAccess
  • AWS CLI Installed (If you need support, see Install AWS CLI on Ubuntu)

Step 01: Getting Started in AWS

With our IAM user created, we are ready to get started

Screen where we have created the IAM User with AdministratorAccess

Let’s use this IAM User with the AdministratorAccess to login in the AWS Console

We are ready in AWS

If we want to play with Docker in AWS, we could create, for example, an AWS EC2 instance with ubuntu and install and use docker on it (see posts about install docker images).

But, let’s continue on our topic, AWS ECR and how to create it:

Step 02: Getting Started with AWS ECR (creation)

Let’s go to the service “ECR” and create one repo for docker images:

https://console.aws.amazon.com/ecs/home#/repositories.

Wellcome page AWS ECR
Giving a Registry Name
When we the registry is created, it give some useful commands

We have the repo created and some instructions to exec on ubuntu:

Step 03: Login in our AWS ECR

At this point is important to remember that we already had configured AWS CLI with the propers AWS ID an secret key to access (after install AWS CLI, the command $ aws configure, explained in Install AWS CLI on Ubuntu) so we can run the commands:

$ aws ecr get-login - region us-west-2

Run the docker login command:

With the Docker Login Successful, we can continue con the next step to push our Docker images in our AWS ECR, our private Docker Registry

Step 04: Build and Push Images on our AWS ECR

So, let’s build docker image, to verify that docker is working after login. The Dockerfile used to build the image was available on my personal GitHub ./myDockerImages and you have detail about it with Running your Own Docker Image on AWS. So, let’s build the image:

$ docker build -t dockerimages .
docker build -t dockerimages . (continue)
build successful docker image
The image was built and in the local registry

Let’s push the image from the local registry to the remote on on AWS, for it, we need to use “docker tag” and “docker push” commands:

$ docker tag    ... (prefix aws registry name)$ docker push   ... (the registry where I am logged in)

Let’s see it in action:

docker tag, and docker push to AWS ECR Registry
docker tag, and docker push to AWS ECR Registry ready

After the docker push, we have the docker image in our AWS ECR Registry

Let’s return to AWS console in ECR service, and we can see that the Docker image is available in our private registry

The image was pushed to AWS ECR

And we could verify the upload time, and the label given for the tag

Step 05: Recover and Pull our Docker Image

The last step we are going to do is remove the docker image from the local repository to ve available for a futures docker pull (sees official doc)

We should first remove the local docker images to be aware about the pull from AWS ECR:

$ aws ecr describe-repositories$ sudo docker images $ sudo docker rmi -f <id>
We will remove first the image from our local registry
Docker image were removed

And the command to recover (pull) our docker image from our private AWS ECR is

$ docker pull <aws_account_id>.dkr.ecr.us-west-2.amazonaws.com/dockerimages:latest

Final Words

I will finish the post at this point. We have highlighted how to create an AWS ECR registry and their purpose as a private registry. Also, we have show in a practical view how to create, login and push docker images in AWS ECR

About how to deal with docker in a broader wide, like in public registries, there are some related post that I am leaving available on the resources section

I hope you enjoyed following this post, an we see on the next one!

Regards!

Pablo

Resources

Official Doc

Related Posts

--

--

Pablo Ezequiel Inchausti

#cloud . #mobile ~} Sharing IT while learning It! ... Opinions are for my own