How to push Docker Image to Public and Private AWS ECR Repository

How to push Docker Image to Public and Private AWS ECR Repository

In this short tutorial we will see how we can push a Docker Image to a private or public registry in ECR.

Step 1: Create an AWS ECR Repository

A Private Repository: It will be managed and accessed by IAM and Registry Policy Permissions and not be accessible by everyone.

OR

A public Repository: It will be accessible by everyone.

Created Repository
Private ECR Repo:

Public ECR Repo:

Step 2: Prepare Docker Image to be pushed to ECR

I have taken an example of a simple Nodejs application got from the internet and created an image on Docker Desktop using following command from the directory where DOCKERFILE for my app is present.

docker image build -t simple-nodejs-app.

Tag the image before pushing to ECR
For Private ECR Repo

docker tag simple-nodejs-app:latest 197317184204.dkr.ecr.us-east-1.amazonaws.com/simple-nodejs-app:latest

For Public ECR Repo

docker tag simple-nodejs-app:latest public.ecr.aws/n4o6g6h8/simple-nodejs-app:latest

Step 3: Authenticate Docker to AWS ECR

You will need AWS credentials configured and required IAM permissions to that AWS user.
For Private ECR Repo:

aws ecr get-login-password –region us-east-1 | docker login –username AWS –password-stdin 197317184204.dkr.ecr.us-east-1.amazonaws.com

For Public ECR Repo:

aws ecr-public get-login-password –region us-east-1 | docker login –username AWS –password-stdin public.ecr.aws/n4o6g6h8

Step 4: Push Image to ECR

For Private ECR Repo:

docker push 197317184204.dkr.ecr.us-east-1.amazonaws.com/simple-nodejs-app:latest

For Public ECR Repo:

docker push public.ecr.aws/n4o6g6h8/simple-nodejs-app:latest

Image pushed to Private ECR Repo

Image pushed to Public ECR Repo

Screenshot

And the image is ready to be used in a container started in an ECS or EKS cluster.

Leave a Reply

Your email address will not be published. Required fields are marked *