AWS

How to Push Local Docker Image to AWS ECR

Docker image is a read-only file containing instructions to create and execute Docker containers. These images can be pushed (uploaded) to any remote registry using the Push command. Elastic Container Registry is a container registry that aids in managing and deploying docker images, it is a fully managed, secure, and Scalable service of AWS.

This article contains a detailed guide on pushing the local image to AWS ECR.

Push Local Docker Image to AWS ECR

Make sure that AWS CLI is installed on the system. Now open Command Prompt in the directory where the Docker image is stored:

Type this command to set up AWS CLI Installation:

> aws configure

Note: It will prompt four different values. Provide the information by copying it from the AWS account.

Copy the required AWS Access Key IP and AWS Secret Access Key by searching IAM in the search bar of the Amazon Management console, click on IAM, and select the option My security credentials:

Open Create access key and copy your Access key and Secret access key:

Now paste these keys in the Command Prompt with respect to the key message, also provide the default region name and set the value of the Default output format to json:

AWS CLI is configured successfully.

The next step is to create ECR, for that search ECR in the search bar of the Amazon Management console and click on Elastic Container Registry:

Click on the button Get started:

Select private or public as per your preference and type the name for ECR:

Leave the rest of the settings as default and click on the Create repository button:

Successfully created ECR will display in the Amazon ECR’s Repositories dashboard, open it by clicking on the Repository name:

It’s time to push the docker image so for that purpose click on View push commands:

Push command wizard will open up containing the commands and procedures for different operating systems, to authenticate and push the images to the repository. From here, copy the authentication token to login into the AWS CLI:

Paste this copied command into the configured Command prompt:

A success message for login can be seen in the output above.

Copy the build command of the docker image from the push commands wizard:

Syntax

> docker build -t <name of docker image>

Paste it in Command Prompt and hit enter:

Copy the tag command to tag the image you want to push into the repository:

Syntax:

> docker tag <image-name> <ECR-registry-name>/<image-name>

Paste it in the Command Prompt:

Copy the push command to push the docker image in the AWS repository from the wizard:

Syntax

> docker push <image-name-in-registry>

Paste it in the Command Prompt:

Image will be pushed to the ECR successfully:

To confirm if the image is pushed successfully or not, open the repository to see the image:

It is visible in the output that the image is pushed successfully, with all the details such as Digest, Pushed at the timestamp, image tag, and artifact type.

Conclusion

Amazon ECR service provides the facility to push the docker image in a few steps using the AWS CLI so that the AWS registry can build and deploy the Docker container using the Docker image. In this article, we pushed a Local Docker Image to ECR.

About the author

Abdul Mannan

I am curious about technology and writing and exploring it is my passion. I am interested in learning new skills and improving my knowledge and I hold a bachelor's degree in computer science.