DEV Community

Cover image for Push Docker Image to AWS ECR
Khaled Md Saifullah
Khaled Md Saifullah

Posted on

Push Docker Image to AWS ECR

Containerization has changed the way we deploy applications. Instead of worrying about dependencies and configurations, Docker lets us package everything into a portable image. But once you have built your image, where do you store it securely for deployment?

That is where AWS ECR (Elastic Container Registry) comes in.
In this blog, you will learn how to build, containerize and push a simple Nginx website to AWS ECR a fundamental DevOps skill for any intermediate developer.

What is AWS ECR?

Amazon Elastic Container Registry (ECR) is a fully managed container image registry service by AWS.

It allows developers to store, manage and deploy Docker container images securely.

You can think of it as GitHub for Docker images instead of hosting your code, it hosts your container images.

How AWS ECR Works

  1. Build your Docker image locally (using Docker CLI)
  2. Authenticate your Docker client with AWS using your credentials
  3. Push your image to your ECR repository
  4. Deploy it on other AWS services like ECS (Elastic Container Service), EKS (Kubernetes) or EC2

When Should You Use AWS ECR?

You should use AWS ECR when:

  • You need a private and secure registry for your organization’s Docker images
  • You are deploying apps to AWS ECS or EKS
  • You want tight integration with IAM for access control
  • You need scalable, managed storage for container images

Project Overview

In this project, we will build a simple static website using Nginx and containerize it using Docker.

Then, we will push that Docker image to AWS ECR for deployment.

Technologies Used:

  • Docker
  • Nginx
  • AWS ECR

Project Structure

.
├── Dockerfile
└── index.html
Enter fullscreen mode Exit fullscreen mode
  • Dockerfile – Defines the Nginx container and copies your static files
  • index.html – Your website’s main page served by Nginx

Dockerfile

FROM nginx:alpine

COPY index.html /usr/share/nginx/html

EXPOSE 80
Enter fullscreen mode Exit fullscreen mode
  • Uses a lightweight Nginx image (nginx:alpine)
  • Copies your static index.html file to the Nginx web directory
  • Exposes port 80 for incoming web traffic

How to Build and Run Docker Image Locally

  1. Build the Docker Image
docker build -t simple-web-app .
Enter fullscreen mode Exit fullscreen mode

Run the Container

docker run -d -p 8080:80 simple-web-app
Enter fullscreen mode Exit fullscreen mode

Access the Website

Open your browser and visit

http://localhost:8080
Enter fullscreen mode Exit fullscreen mode

You will see your static index.html page being served by Nginx 🎉

Deploying on AWS ECR

Once you have verified it works locally, you can deploy this image to AWS using the following flow:

  1. Push the Image to Amazon ECR (Elastic Container Registry):
aws ecr create-repository --repository-name simple-web-app
Enter fullscreen mode Exit fullscreen mode
aws ecr get-login-password --region <region> | \
docker login --username AWS --password-stdin <aws_account_id>.dkr.ecr.<region>.amazonaws.com
Enter fullscreen mode Exit fullscreen mode
docker tag simple-web-app:latest <aws_account_id>.dkr.ecr.<region>.amazonaws.com/simple-web-app:latest
docker push <aws_account_id>.dkr.ecr.<region>.amazonaws.com/simple-web-app:latest
Enter fullscreen mode Exit fullscreen mode
  1. Pull the Image from ECR (From Any Machine or Server) Once the image is in ECR, you can pull it from anywhere (e.g., EC2 instance, ECS task, or local machine):

Authenticate again:

aws ecr get-login-password --region <region> | \
docker login --username AWS --password-stdin <aws_account_id>.dkr.ecr.<region>.amazonaws.com
Enter fullscreen mode Exit fullscreen mode

Pull the image:

docker pull <aws_account_id>.dkr.ecr.<region>.amazonaws.com/simple-web-app:latest
Enter fullscreen mode Exit fullscreen mode

Run the image:

docker run -d -p 80:80 <aws_account_id>.dkr.ecr.<region>.amazonaws.com/simple-web-app:latest
Enter fullscreen mode Exit fullscreen mode

Now your container is running the image directly from AWS ECR.

Why AWS ECR is a Great Choice?

  • Fully managed by AWS: no need to host your own registry
  • Private and secure: integrates with AWS IAM for access control
  • Scalable and reliable: backed by AWS infrastructure
  • Cost efficient: pay only for the storage you use
  • Seamless integration with ECS, EKS and CI/CD pipelines

Conclusion

This project is a simple yet powerful demonstration of how to containerize and deploy web applications using Docker, Nginx and AWS ECR.

You learned how to:

  • Build and run a Docker container locally
  • Push it to AWS ECR securely
  • Pull and deploy it anywhere

Whether you are a developer learning DevOps or planning to deploy production workloads on AWS, mastering ECR and container workflows is an essential step toward modern cloud infrastructure.

Authors

Top comments (0)