π Push Your Python Docker Image to AWS ECR (Elastic Container Registry)
In this tutorial, youβll learn how to upload your Python Docker image to AWS Elastic Container Registry (ECR) β
a fully managed Docker image repository by Amazon Web Services.
This is the final step before deploying your app to EC2, ECS, or any cloud service. π
πͺ Step 1: Install AWS CLI
First, ensure you have the AWS CLI installed in your Ubuntu/WSL terminal.
sudo apt update
sudo apt install awscli -y
Once installed, verify it:
aws --version
πͺ Step 2: Configure AWS CLI
Now configure your AWS account credentials:
aws configure
When prompted, enter:
AWS Access Key ID [None]: YOUR_ACCESS_KEY
AWS Secret Access Key [None]: YOUR_SECRET_KEY
Default region name [None]: ap-south-1
Default output format [None]: json
π You can find your Access Key ID and Secret Key
under IAM β Users β Security Credentials in your AWS Console.
πͺ Step 3: Create a Repository in AWS ECR
Go to your AWS Management Console β Elastic Container Registry β Repositories.
- Click on Create Repository.
- Repository name:
python-hello - Visibility: Private
- Region:
ap-south-1 - Click Create.
After creation, copy your ECR URI β it looks like:
807650717461.dkr.ecr.ap-south-1.amazonaws.com/python-hello
πͺ Step 4: Authenticate Docker with AWS ECR
Run this command to log Docker into ECR:
aws ecr get-login-password --region ap-south-1 | \
docker login --username AWS --password-stdin 807650717461.dkr.ecr.ap-south-1.amazonaws.com
β You should see:
Login Succeeded
πͺ Step 5: Tag Your Local Docker Image
Now tag your existing image (from the previous post) with the ECR repo name:
docker tag python-hello:latest 807650717461.dkr.ecr.ap-south-1.amazonaws.com/python-hello:latest
πͺ Step 6: Push Your Image to AWS ECR
Now push it to the ECR repository:
docker push 807650717461.dkr.ecr.ap-south-1.amazonaws.com/python-hello:latest
It will take a few moments to upload depending on your internet speed.
Once complete, youβll see your image in the AWS Console under your repository.
πͺ Step 7: Verify in AWS Console
- Open AWS Console β Elastic Container Registry β Repositories
- Click on
python-hello - Youβll see your image tagged as
latest
π Thatβs it! Your Docker image is now securely stored in AWS ECR.
π§© Step 8 (Optional): Run Image from ECR
If you want to test the pulled image:
docker pull 807650717461.dkr.ecr.ap-south-1.amazonaws.com/python-hello:latest
docker run -d -p 8000:8000 807650717461.dkr.ecr.ap-south-1.amazonaws.com/python-hello:latest
Now visit:
π http://localhost:8000
Youβll again see: Hello World from Docker + Python!
π― Summary
Youβve now learned how to build, tag, and push a Docker image to AWS ECR.
This is a crucial step before deploying your app on AWS ECS or EC2.
In the next post, weβll cover Deploying your ECR image to AWS ECS (Elastic Container Service).
π Next Learning Path
- β Install Docker inside WSL
- β Build & Run Python Apps with Docker
- β Push Docker Image to AWS ECR (Youβre here!)
- π Deploy Docker Container to AWS ECS
