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.
Creation process
You can create an ECR Repository following this guide.
We will save an image of ubuntu
First, pull the docker image:
docker pull ubuntu:20.04
You should get an output similar to this:
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
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
The output should be:
Then push the image:
docker push YOUR_AWS_ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/ecr-repository
The output should be:
You can confirm it's creation in the AWS 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
Assuming you used the CloudFormation template from this lesson, delete the repository by running:
aws cloudformation delete-stack --stack-name ecr-repository
Top comments (0)