Docker Tutorial

How to Connect Amazon ECR to EC2 and Deploy Your Docker Project (Step-by-Step Guide)

How to Connect Amazon ECR to EC2 and Deploy Your Docker Project (Step-by-Step Guide)

Updated: November 2025 by Admin

In this guide, you’ll learn how to connect your Amazon ECR (Elastic Container Registry) to an EC2 instance and deploy your Docker project β€” step by step! πŸ³πŸ’»


βœ… Step 1: Prerequisites

  • You already have your project uploaded to Amazon ECR.
  • You have a running EC2 instance (Ubuntu).
  • AWS CLI is installed and configured.
  • Docker is installed on your EC2 instance.

βœ… Step 2: Connect to Your EC2 Instance

Use your terminal or PowerShell to SSH into your EC2 instance:

ssh -i "your-key.pem" ubuntu@your-ec2-public-ip

Once you’re inside, update your packages:

sudo apt update && sudo apt upgrade -y

βœ… Step 3: Install Docker (if not installed)

sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker ubuntu

Then log out and log back in to apply Docker permissions.


βœ… Step 4: Log in to Amazon ECR

Your ECR repository details are:

  • Repository URI: 086971354648.dkr.ecr.eu-central-1.amazonaws.com/python/project
  • Region: eu-central-1

Run the following command to authenticate your EC2 Docker client with Amazon ECR:

aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin 086971354648.dkr.ecr.eu-central-1.amazonaws.com

βœ… You should see a message like:

Login Succeeded


βœ… Step 5: Pull Your Docker Image from ECR

Now that you’re logged in, pull your Docker image from your ECR repository:

docker pull 086971354648.dkr.ecr.eu-central-1.amazonaws.com/python/project:latest

This will download the image you uploaded earlier to your EC2 instance.


βœ… Step 6: Run the Docker Container

Once the image is pulled, you can start the container using:

docker run -d -p 80:80 086971354648.dkr.ecr.eu-central-1.amazonaws.com/python/project:latest

πŸ’‘ The -d flag runs the container in detached mode, and -p 80:80 maps your EC2’s port 80 to the container’s port 80.


βœ… Step 7: Verify Your Deployment

Check if the container is running:

docker ps

If it’s running, open your EC2 public IP in a browser:

http://your-ec2-public-ip

πŸŽ‰ You should now see your live application running directly from your Docker image on Amazon EC2!


βœ… Step 8: Make Sure It Runs After Reboot

If you want your container to restart automatically after an EC2 reboot, run:

docker update --restart=always $(docker ps -q)

🎯 Summary

  • Configured AWS CLI with your access keys
  • Connected EC2 to ECR
  • Pulled Docker image and ran the container
  • Deployed the live app accessible via EC2 public IP

And that’s it! Your Docker project from ECR is now live on EC2 πŸš€

βœ… Repository: 086971354648.dkr.ecr.eu-central-1.amazonaws.com/python/project

βœ… Region: eu-central-1


Written by Admin β€” Cloud DevOps Engineer | AWS | Docker | EC2 | ECR

Leave a Reply

Your email address will not be published. Required fields are marked *