Pushing Images to ECR
Introduction and Goal
Welcome to the third lesson in our course on Working with Container Registries. In the previous lesson, you created a secure ECR repository with vulnerability scanning and immutable tags enabled. Now you have an empty repository waiting for container images, but how do you actually get your applications into ECR?
This lesson bridges that gap by teaching you the complete workflow for getting locally built Docker images into your ECR repository. We'll start with a simple Flask web application, build it into a Docker image on your local machine, authenticate Docker to work with ECR, tag the image with the proper ECR naming convention, and finally push it to your repository.
By the end of this lesson, we'll execute the full sequence: docker build to create your image locally, aws ecr get-login-password to authenticate, docker tag to prepare the image for ECR, and docker push to upload it. This workflow forms the foundation for all ECR operations, whether you're working manually or setting up automated CI/CD pipelines.
The sample application we'll use is a minimal Flask web server that responds with "Hello from ECR!" when accessed. While simple, this demonstrates the complete process we'll use for any containerized application, from microservices to complex web applications.
Prerequisites and Repo Check
Before pushing your first image to ECR, you need to confirm that your repository from the previous lesson exists and gather the specific details required for the push process. The repository URI you created earlier contains your AWS account ID and region, both of which are essential for the tagging and authentication steps.
Run this command to verify your repository exists and note its URI:
The output should show your repository details, including the repositoryUri field that looks like 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-web-app. This URI contains three critical pieces of information: your 12-digit AWS account ID (123456789012), your region (us-east-1), and your repository name (my-web-app). We'll need these components for the authentication and tagging steps.
Your AWS CLI must be configured with credentials that have ECR permissions, specifically ecr:GetAuthorizationToken for authentication, ecr:BatchCheckLayerAvailability and ecr:PutImage for pushing images, and ecr:InitiateLayerUpload and ecr:UploadLayerPart for the actual upload process.
In the CodeSignal environment, Docker, the AWS CLI, and all necessary permissions are pre-configured for you. However, understanding these requirements is important when you work on your own development machine or set up CI/CD pipelines in production environments.
