DEV Community

Mubbashir Mustafa
Mubbashir Mustafa

Posted on • Updated on

Push/Publish Docker images to AWS ECR

Amazon Elastic Container Registry (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.


If you don't have an existing dockerized application. Clone this sample nodejs application to test things out.


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 same tags)

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 we need to use these commands one by one to build, tag and push our 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, we 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". We will need it later on.
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", provide them one by one (copied in the previous step). You can skip the next two questions (default region and default output format).
Configure AWS CLI with AWS Access Key

Once aws cli has been configured, now we can run the push commands. Open up the terminal and make sure you are inside the app 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

Discussion (0)