Push/Publish Docker images to AWS ECR
Tags: aws, beginners, devops, docker
Published: 2021-09-03 17:44:43

---
series: Containers on AWS
---
Amazon Elastic Container Registry ([AWS ECR](https://aws.amazon.com/ecr/)) is a container registry service where you store, manage, share, and deploy your container images (like DockerHub). Consider it as [npmjs](https://www.npmjs.com/) of containers instead of JS packages. AWS ECR lets you publish private as well as public images. 

Before you proceed, it's assumed that you already have a containerized application. If you don't have one, you can [clone this sample nodejs application.](https://github.com/mubbashir10/aws-proton-nodejs-sample) 

Sign in to your AWS console and search for AWS ECR
![Access AWS ECR from AWS Console](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/48lyzjc5q9dr5338tvdd.png)

From the AWS ECR console, click 'Get Started'
![Create new AWS ECR repository](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/khnj681nsbcimbso5mr6.png)


### Options
1. Visibility settings: select Private or Public

2. Repository name: give any meaningful name

3. Tag immutability: when enabled, it will prevent tags from being overwritten by new pushes (when pushed with the same tag)

Enable Image scan setting to enable vulnerability scan after the image is pushed
![AWS ECR Create Repository](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nhc7rh6jzi11j7a6zuyz.png)

Enable to use [AWS KMS](https://aws.amazon.com/kms/) for encryption
![AWS ECR Create Repository](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/czpdk4ovqqeppaq14cxc.png)


Once the repository is created, it will take you back to the repositories list. Select the newly created repository and then click on the "View push commands" button. 
![AWS ECR Push repo Commands](https://dev-to-uploads.s3.amazonaws.com/i/3erhtq4xkerjn568kkw2.png)

Now you need to use these commands one by one to build, tag, and push your container image. But before proceeding make sure you have the latest version of [AWS CLI](https://aws.amazon.com/cli/) installed. 

Use the following command to check that AWS CLI is correctly installed on your system.

`aws --version`

It would output something like this. Your version could be different, it depends when you are reading this article.
![AWS CLI Version](https://dev-to-uploads.s3.amazonaws.com/i/1gwu0iqngc24cfkk3mzy.png)

Next, you need to create 'Access Keys'. For that, go to "My Security Credentials" from the dropdown with your username.
![AWS Access Key to Connect AWS CLI](https://dev-to-uploads.s3.amazonaws.com/i/ss77ywl227cpd592g06e.png)

Click on "Create New Access Key", it will create a new key for you.
![New AWS Access Key](https://dev-to-uploads.s3.amazonaws.com/i/dxhcmh3asg4vm02wadar.png)

Copy "Access Key ID" and "Secret Access Key"
![AWS Access Key/Private Key](https://dev-to-uploads.s3.amazonaws.com/i/tq1e2xdvsrb22zpcmbog.png)

Now go back to your terminal and enter the following command
`aws configure`

It will ask for "Access Key ID" and "Secret Access Key", "Default region", provide them one by one. You can skip the default output format.
![Configure AWS CLI with AWS Access Key](https://dev-to-uploads.s3.amazonaws.com/i/x530988hv1gjvmrf9zbp.png)


Once the AWS CLI has been configured, you can run the push commands. Open up the terminal and make sure you are inside the containerized app's root directory. Run each command shown in the popup opened up by clicking the "View push commands" button. Please note that the commands in the screenshot could be different than what you see in your popup and it's totally fine.
![AWS ECR push docker image to repo](https://dev-to-uploads.s3.amazonaws.com/i/x0mfboq7c9rt2eqrx3wh.png)

*If your 'Dockerfile' is named something other than 'Dockerfile', you will have to specify it using `-f` flag (see below).
![AWS ECR Push docker image success](https://dev-to-uploads.s3.amazonaws.com/i/cadjc2gxswqoshznw592.png)

---
Let's connect: 

Linkedin: [https://www.linkedin.com/in/mubbashir10/](https://www.linkedin.com/in/mubbashir10/) 

Twitter: [https://twitter.com/mubbashir100](https://twitter.com/mubbashir100)