• Home
  • Disclaimer
  • Contact
  • Archives
  • About
  • Subscribe
  • Support
  • Advertise

Kernel Talks

Unix, Linux, & Cloud!

  • How-to guides
    • Howto
    • Disk management
    • Configurations
    • Troubleshooting
  • OS
    • HPUX
    • Linux
  • Miscellaneous
    • Software & Tools
    • Cloud Services
    • System services
    • Virtualization
  • Certification Preparations
    • AWS Certified Solutions Architect – Associate
    • AWS Certified Solutions Architect – Professional
    • AWS Certified SysOps Administrator – Associate
    • AWS Certified Cloud Practitioner
    • Certified Kubernetes Administrator
    • Hashicorp Certified Terraform Associate
    • Oracle Cloud Infrastructure Foundations 2020 – Associate
  • Tips & Tricks
  • Linux commands
You are here: Home / Cloud Services

Amazon ECR: Creating repository and pushing first container image

Published: November 18, 2020 | Modified: December 15, 2020



A quick rundown on how to create an Amazon ECR repository and push container image to it.

ECR HowTos!

What is Amazon ECR?

Amazon ECR, i.e., Elastic Container Registry, is a fully managed container image registry service provided by AWS. It is integrated with Amazon ECS so that developers can have a fully managed container platform by AWS. You can visualize it as your own docker hub.

Browse through our Amazon ECS related articles here.

How to create ECR repository?

Amazon ECR has its own home under Amazon ECS dashboard.

  • Login to Amazon ECR dashboard; click on Get started button
  • Or login to the Amazon ECS dashboard
    • Click on Repositories in the left navigation panel
    • Click on the Create repository button on the repository page.
  • You should be presented with the below screen –
ECR repository create screen

Different configurations are –

  • Repository name: It will follow the below format
    • account-id.dkr.ecr.region.amazonaws.com/name
  • Tag immutability: Prevents overwriting images with the same tags in the subsequent push.
  • Image scan settings: Enable it to scan images as soon as they are pushed to ECR for vulnerabilities.
  • Encryption settings: Use KMS or let ECR use default encryption for images once pushed to ECR.

Click Create repository button.

A repository should be created, and the ECR dashboard should enlist the newly created repository. Please select it and click on the View push commands button to get the authentication token, login, and push commands. These are ready-made commands for you to ease your tasks.

Getting ECR commands from AWS console

ECR will provide you with 4 commands pre-populated with the correct repository name. The explanation is given with each command is pretty self-explanatory.

ECR push commands

How to push container image to Amazon ECR?

Now, we will use these commands to push the test container image to Amazon ECR. I will be using the Amazon Linux EC2 instance for this exercise. Make sure you have docker and aws-cli installed, configured, and running fine on the EC2 instance. Also, make sure EC2 is having at least an AmazonEC2ContainerRegistryPowerUser role attached so that ECR push works fine if you are using EC2 roles for authentication.

Step 1.

Get the authentication token and log in using the docker command. Its taken care of by the first command we saw in the previous screenshot. It has a two-part. First, aws command gets the authentication details and passes them to the second docker command for login.

[root@ip-10-0-0-226 ~]# aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 3xxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
Step 2.

Tag container image. I am assuming you already have an image created using Dockerfile. For testing, I pulled the Nginx image from DockerHub and tagged it.

[root@ip-10-0-0-226 ~]# docker tag nginx:latest 3xxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/webserver:latest

Verify image tags.

[root@ip-10-0-0-226 ~]# docker images
REPOSITORY                                               TAG                 IMAGE ID            CREATED             SIZE
3xxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/webserver   latest              daee903b4e43        9 hours ago         133MB
nginx                                                    latest              daee903b4e43        9 hours ago         133MB
Step 3.

Push image to ECR using docker push command.

[root@ip-10-0-0-226 ~]# docker push 3xxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/webserver:latest
The push refers to repository [3xxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/webserver]
b9e73ac5343e: Pushed
5887d03dfc3d: Pushed
e3a971c30b12: Pushed
32048dd980c7: Pushed
f5600c6330da: Pushed
latest: digest: sha256:bb84ff0786cd1dbde780d84f6bf76bfdef36fe8ffa658f7f5c48e39363b4d500 size: 1362

If you come back to the AWS console and check under the repository, you should be seeing this latest pushed image there.

As you can see, since the Image scan was enabled, ECR scanned the image for vulnerabilities as soon as it was pushed. And added a report in the same view. Click on the image tag for checking image details.

Image details

If you don’t enable the Image scan setting, then the manual scan can be done by clicking the Scan button on the Images details screen.

Another point to note here is ECR showing image size as 53.61MB, whereas it was reported as 133MB on EC2 command outputs. This is because docker compresses the image layers when pushing the image to the repository. Note about the same can be found here in AWS documentation.

How to pull container image from ECR?

It’s a simple docker pull command. Provided you have EC2 instance and docker daemon properly setup for authentication (as mentioned above).

[root@ip-10-0-0-226 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
[root@ip-10-0-0-226 ~]# docker pull 3xxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/webserver
Using default tag: latest
latest: Pulling from webserver
852e50cd189d: Pull complete
a29b129f4109: Pull complete
b3ddf1fa5595: Pull complete
c5df295936d3: Pull complete
232bf38931fc: Pull complete
Digest: sha256:bb84ff0786cd1dbde780d84f6bf76bfdef36fe8ffa658f7f5c48e39363b4d500
Status: Downloaded newer image for 3xxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/webserver:latest
3xxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/webserver:latest
[root@ip-10-0-0-226 ~]# docker images
REPOSITORY                                               TAG                 IMAGE ID            CREATED             SIZE
3xxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/webserver   latest              daee903b4e43        10 hours ago        133MB
⇠ Previous article
Assorted list of resources to ease your AWS tasks
Next article ⇢
Creating Application Load Balancer in AWS

Related stuff:

  • AWS EC2, S3, RDS revision before the CSA exam
  • How to create S3 bucket in AWS
  • Configuring ALB authentication with Amazon Cognito for ConsoleMe webapp
  • Scaling with AWS PrivateLink
  • How to release the Elastic IP in AWS
  • Creating first AWS Lambda function
  • Amazon ECS basics for beginners
  • AWS VPC Creation along with screenshots
  • Preparing for 1Z0-1085-20 Oracle Cloud Infrastructure Foundations 2020 Associate Exam
  • How to resolve the MFA entity already exists error
  • How to open port on AWS EC2 Linux server
  • Understanding the basics of Lambda Function URLs

Filed Under: Cloud Services Tagged With: Amazon ECR for beginner, ECR login in docker, ECR pull, ECR push

If you like my tutorials and if they helped you in any way, then

  • Consider buying me a cup of coffee via paypal!
  • Subscribe to our newsletter here!
  • Like KernelTalks Facebook page.
  • Follow us on Twitter.
  • Add our RSS feed to your feed reader.

Share Your Comments & Feedback: Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get fresh content from KernelTalks

  • Email
  • Facebook
  • RSS
  • Twitter

Get Linux & Unix stuff right into your mailbox. Subscribe now!

* indicates required

This work is licensed under a CC-BY-NC license · Privacy Policy
© Copyright 2016-2023 KernelTalks · All Rights Reserved.
The content is copyrighted to Shrikant Lavhate & can not be reproduced either online or offline without prior permission.