DEV Community

Cover image for Push/Publish Docker images to AWS ECR
Mubbashir Mustafa
Mubbashir Mustafa

Posted on • Updated on

Push/Publish Docker images to AWS ECR

Amazon Elastic Container Registry (AWS ECR) is a container registry service where you store, manage, share, and deploy your container images (like DockerHub). Consider it as npmjs 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.

Sign in to your AWS console and search for AWS ECR
Access AWS ECR from AWS Console

From the AWS ECR console, click 'Get Started'
Create new AWS ECR repository

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

Enable to use AWS KMS for encryption
AWS ECR Create Repository

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

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 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

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

Click on "Create New Access Key", it will create a new key for you.
New AWS Access Key

Copy "Access Key ID" and "Secret Access Key"
AWS Access Key/Private Key

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

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

*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


Let's connect:

Linkedin: https://www.linkedin.com/in/mubbashir10/

Twitter: https://twitter.com/mubbashir100

Top comments (0)