Cloud and DevOps

How to push Docker images into AWS ECR?

By the Zehntech team17 Sep 2019Updated 30 Jan 20242 min read
How to push Docker images into AWS ECR?

Introduction: push Docker images to a registry

Docker is a container platform that lets you build, test, and deploy distributed applications. A Docker container is a running instance of an image. You create a Docker image from a text file called a Dockerfile. It holds commands and instructions, line by line. In this tutorial, we show how to push Docker images into the AWS ECR registry.

Docker images create Docker containers. An image holds the application files and configuration files. It can also build on other images, such as Ubuntu, and it includes the Dockerfile.

A Dockerfile consists of many commands. Docker runs them step by step, each in its own temporary container. Docker removes each container automatically once its command finishes. A main container holds all these sub-containers while Docker creates and deletes them.

First, make sure you have what you need. Then follow the four steps below. You can also read about the AWS cloud platform and our custom software services.

Prerequisites

  • A Docker image
  • AWS login credentials
  • AWS ECR registry
  • Permissions on an IAM role to access ECR

Steps to push Docker images into ECR

  • Step-1: AWS Authentication
  • Step-2: Get Docker images
  • Step-3: Tagging
  • Step-4: Push the image into ECR

AWS Authentication

  • First, log in to AWS ECR from the Docker client. To authenticate an Amazon ECR registry to Docker, run the command “aws ecr get-login-password”.

    Note: “Specify the AWS username and registry URI when you pass the auth token to the command for docker login.”

    Use this command to authenticate with the AWS ECR registry:

    aws ecr get-login-password --region us-west-1 | docker login --username zehntech --password-stdin aws_account_id.dkr.ecr.us-west-1.amazonaws.com

Get Docker Images

Next, run the command below in your Docker CLI tool to get the list of Docker images:

docker images

This lists all the Docker images in your Docker environment.

Then copy the Docker image ID that you want to push into the AWS ECR registry. You can find an image by its “repository:tag” value or by its image ID in the output of the command above.

Also Read:

Docker Containers Running Slowly? Try These Tricks!
How to Speed Up Software Delivery Processes With Docker?
How to remove machine dependency for LAMP development using Docker?

Tagging

You can assign your own metadata to each repository in the form of tags. Tags help you manage your Amazon ECR repositories.

Next, tag your image with the Amazon ECR registry. Note: “The name of the repository should be the same as the name of your image.“

Use this command to tag the image:

docker tag e6ge4d780n39 aws_account_id.dkr.ecr.region.amazonaws.com/zehntech-app

Here, e6ge4d780n39 is the tag of the image, and zehntech-app is the id of the image.

Push the image into ECR

Finally, use this command to push Docker images into ECR:

docker push aws_account_id.dkr.ecr.region.amazonaws.com/zehntech-app

Then review the Amazon ECR registry to confirm. The image should be visible there.

Note: You can apply multiple tags per image in AWS ECR. The default maximum value is 100 tags.

Summary

In this tutorial, we authenticated to the Amazon ECR registry from the Docker CLI with the “aws ecr get-login-password” command. Then we tagged the Docker image. Finally, we pushed the image into the ECR registry.

Docker

Need help with your infrastructure?

We build and run custom systems on AWS, Azure and Docker.