Docker Tutorial

How to Install and Configure AWS CLI on Ubuntu or WSL (Step-by-Step Guide)

πŸš€ 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

Leave a Reply

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