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
