DEV Community

Cover image for Day 28: Creating a Private ECR Repository
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

Day 28: Creating a Private ECR Repository

Lab Information

The Nautilus DevOps team has been tasked with setting up a containerized application. They need to create a private Amazon Elastic Container Registry (ECR) repository to store their Docker images. Once the repository is created, they will build a Docker image from a Dockerfile located on the aws-client host and push this image to the ECR repository. This process is essential for maintaining and deploying containerized applications in a streamlined manner.

Create a private ECR repository named datacenter-ecr. There is a Dockerfile under /root/pyapp directory on aws-client host, build a docker image using this Dockerfile and push the same to the newly created ECR repo, the image tag must be latest.

Lab Solutions

πŸ”Ή STEP 1: Verify Docker & AWS CLI

On aws-client, confirm Docker is running:

docker --version
Enter fullscreen mode Exit fullscreen mode

Confirm AWS CLI is configured:

aws sts get-caller-identity

πŸ”Ή STEP 2: Create the ECR Repository

Run:

aws ecr create-repository \
  --repository-name datacenter-ecr \
  --region us-east-1
Enter fullscreen mode Exit fullscreen mode

You will get output containing:

"repositoryUri": "123456789012.dkr.ecr.us-east-1.amazonaws.com/datacenter-ecr"

πŸ“Œ Copy the repositoryUri β€” you’ll need it.

πŸ”Ή STEP 3: Authenticate Docker to ECR

Run:

aws ecr get-login-password --region us-east-1 \
| docker login --username AWS --password-stdin \
022390610537.dkr.ecr.us-east-1.amazonaws.com/datacenter-ecr
Enter fullscreen mode Exit fullscreen mode

βœ… Expected output:

Login Succeeded

πŸ”Ή STEP 4: Build the Docker Image

Navigate to the directory with the Dockerfile:

cd /root/pyapp

# Build the image:

docker build -t datacenter-ecr:latest .

# Verify the image exists:

docker images
Enter fullscreen mode Exit fullscreen mode

You should see:

datacenter-ecr latest

πŸ”Ή STEP 5: Tag the Image for ECR

Tag the image using the repository URI:

Run:

docker tag datacenter-ecr:latest \
022390610537.dkr.ecr.us-east-1.amazonaws.com/datacenter-ecr:latest
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή STEP 6: Push the Image to ECR

Run:

docker push 022390610537.dkr.ecr.us-east-1.amazonaws.com/datacenter-ecr:latest
Enter fullscreen mode Exit fullscreen mode

βœ… You should see layer upload progress and a successful push.

πŸ”Ή STEP 7: Verify Image in ECR

Run:

aws ecr list-images \
  --repository-name datacenter-ecr \
  --region us-east-1
Enter fullscreen mode Exit fullscreen mode


Resources & Next Steps
πŸ“¦ Full Code Repository: KodeKloud Learning Labs
πŸ“– More Deep Dives: Whispering Cloud Insights - Read other technical articles
πŸ’¬ Join Discussion: DEV Community - Share your thoughts and questions
πŸ’Ό Let's Connect: LinkedIn - I'd love to connect with you

Credits
β€’ All labs are from: KodeKloud
β€’ I sincerely appreciate your provision of these valuable resources.

Top comments (0)