DEV Community

Oluwafemi Lawal
Oluwafemi Lawal

Posted on

Creating Your Private Versions of Public Docker Images in ECR

Why do this?

One reason could be avoiding Docker Hub's free tier rate limits. If your team uses free Docker Hub, you might run into rate limits while pulling images into something like AWS CodeBuild. The rate limit is set to 100 pulls per 6 hours per IP address if you are anonymous and 200 pulls per 6 hours for authenticated users with a Docker ID.
Example of Docker Hub CodeBuild rate limit error

Creation process

You can create an ECR Repository following this guide.
We will save an image of ubuntu
Ubuntu docker hub page
First, pull the docker image:

docker pull ubuntu:20.04
Enter fullscreen mode Exit fullscreen mode

You should get an output similar to this:
Docker Pull
Then create a target image tag that refers to the source image:

docker tag ubuntu:20.04 YOUR_AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/ecr-repository
Enter fullscreen mode Exit fullscreen mode

Before you can push to ECR, you have to authenticate:

aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin YOUR_AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com
Enter fullscreen mode Exit fullscreen mode

The output should be:
Authentication success
Then push the image:

docker push YOUR_AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/ecr-repository
Enter fullscreen mode Exit fullscreen mode

The output should be:
ECR Push output
You can confirm it's creation in the AWS console:
ECR Repo in console

Cleanup

Always remember to clean up resources you do not need.
First delete the image:

aws ecr batch-delete-image --repository-name ecr-repository --image-ids imageTag=latest
Enter fullscreen mode Exit fullscreen mode

Delete image output
Assuming you used the CloudFormation template from this lesson, delete the repository by running:

aws cloudformation delete-stack --stack-name ecr-repository
Enter fullscreen mode Exit fullscreen mode

Top comments (0)