How To Push A Docker Image To Amazon ECR?
Last Updated :
26 Feb, 2024
We go over how to submit a Docker image to the Amazon Elastic Container Registry (ECR) in this tutorial. By offering a safe, scalable registry for storing and distributing Docker images inside the AWS ecosystem, Amazon ECR streamlines container management. To upload and maintain your containerized applications in Amazon ECR with ease, simply follow these instructions.
What is Docker?
Docker is a platform where it is easier to make, run, and deploy applications using containers. It simplifies the process of building, running, and deploying applications by providing a consistent environment across different platforms and infrastructure.
What is Amazon ECR?
Amazon Elastic Container Registry (ECR) is a fully managed Docker container service registry provided by Amazon Web Services (AWS). It can store, manage, and deploy container images securely. It is a reliable platform for storing and managing containerized applications.
How to push a Docker image to Amazon ECR?
Prerequisites
- Docker Hub account
- Base knowledge of Docker
- AWS account
- AWS CLI installed
- Configure AWS
- Docker CLI
Step 1: Build a Docker image
To demonstrate how to push a Docker image into ECR, we'll make a simple Docker image. Create a simple Docker image using the following link given below.
Link:- https://www.geeksforgeeks.org/create-docker-image/
After creating the docker image run the image and access it through localhost.
Step 2: Creating the AWS ECR repository
Log in to the AWS console and go to the AWS ECR. Then click Get Started to create a repository.
ECR get startedIn the General settings , set the visibility settings to Private. Then set the Repository name according to your choice , Here we are naming it as " gfg-ecr " . Leave other settings as it is.
Name the ECRClick Create repository on the bottom.
Create repositoryAn empty repository now created named "gfg-ecr " .
Repository createdStep 3: Set up the image to be pushed
Here we will push a simple dokcer image of index.html that listens on port 8080. The root directory has a Dockerfile. We will use it to build an image.
The Dockerfile contains the following commands:
FROM nginx:alpine
COPY index.html /usr/share/nginx/html
EXPOSE 80
The index.html file contains:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>How to create docker image</title>
</head>
<body>
<H1>Hey geeks to create a docker image you have to write a Dockerfile and then build it using
docker command .
</H1>
</body>
</html>

Step 4: Build the container image and deploy locally
The container image will be built using the command below.
docker image build -t <image_name> .
The dot indicates that the Dockerfile image resides in the current directory.
After the build is finished deploy your container locally in port 8080 with the following command
docker run -d --name <container_name> -p 8080:80 <image_name>
Step 5: Push image to the Amazon ECR repository
We need to authenticate the Docker client to the registry. To proceed with the authentication, we would run a get-login-password command in the CLI to retrieve the token and then pass it to the docker login command.
(Get-ECRLoginCommand).Password | docker login --username AWS --password-stdin 046818881351.dkr.ecr.eu-north-1.amazonaws.com
After the build completes, tag your image so you can push the image to this repository:
docker tag gfg-ecr:latest 046818881351.dkr.ecr.eu-north-1.amazonaws.com/gfg-ecr:latest
Run the following command to push this image to your newly created AWS repository:
docker push 046818881351.dkr.ecr.eu-north-1.amazonaws.com/gfg-ecr:latest
Push commands in the ECR
Similar Reads
How to Push a Container Image to a Docker Repository?
In this article we will look into how you can push a container image to a Docker Repository. We're going to use Docker Hub as a container registry, that we're going to push our Docker image to. Follow the below steps to push container Image to Docker repository:Step 1: Create a Docker Account The f
3 min read
How to Manage Storage and Costs in Amazon ECR?
In the past, developers would often get frustrated as they sought to run their code from their local machines into the production environment. to run their code from their local machines into the production environment. This resulted from having different setups of software in the production environ
13 min read
How to Install Docker on Amazon Linux
Docker is a tool which helps to automate the deployment of applications in containers to make sure that particular applications can work efficiently in different environments without any errors.It helps developers to build, ship, and run application faster and more reliable way. In this article, we
3 min read
How to Push Docker Image to AWS ECS Fargate Using Terraform?
ECS helps to manage containers and this service is provided by AWS, it allows users to easily manage and scale docker containers on a cluster of ec2 instances, without having to manage the underlying infrastructure. What is ECS Fargate?Fargate provides a way to run containerized applications on a se
8 min read
How to Export and Import Docker Containers and images
In software development, flexibility and portability are important. Suppose youâve built a perfect application in a Docker container on your development machine and now you need to move this same setup to a colleagueâs machine or a production server. How do you ensure your application, and all its d
6 min read
How to Publish Docker Image to Dockerhub Using Github Actions?
Pre-requisites: GitHub Actions, Docker Hub Publishing Docker images to Docker Hub using GitHub Actions is a simple and efficient process that can automate your image-building and publishing process. What are Github Actions?GitHub Actions is a CI/CD (Continuous Integration/Continuous Deployment) plat
3 min read
How To See Docker Image Contents?
In the evolving world of containerization, Docker has emerged as a tool for packaging and deploying applications. While creating and sharing Docker images has streamlined the development and deployment process. Contents of a Docker image are important for troubleshooting, optimizing, and ensuring se
3 min read
How to Load a Docker Image: Step-by-Step Guide
Docker is essential for managing and deploying apps in containerized environments. One of Docker's core functions is working with images, which are standalone, portable, and executable software packages. The 'docker image load' command is a crucial tool for loading Docker images from a tarball into
4 min read
How to Generate a Dockerfile from an Image?
When working with Docker, you may sometimes need to recreate or reverse-engineer a Dockerfile from an existing image. While Docker doesnât offer a direct method to generate a Dockerfile from an image, you can still extract useful information from the imageâs layers and commands. This guide will walk
5 min read
How can I Make my own Base Image for Docker?
Developing a custom base image for Docker is a significant opportunity to make your development and deployment workflows more efficient. A base image is a foundation for building with DockisPrimary TerminologiesDocker: Docker is an open-source platform that works with the medium of delivering softwa
5 min read