Pulling and Running Images
Introduction and Lesson Outcome
Welcome to the fourth lesson in our course on Working with Container Registries. You've made excellent progress building your ECR expertise, learning what Amazon ECR is, creating secure repositories, and mastering the complete workflow of building and pushing Docker images to ECR. Now that you have container images stored securely in ECR, it's time to learn the other half of the container workflow: pulling and running those images.
Understanding the pull and run workflow is crucial because it completes the full container lifecycle. While pushing images to ECR represents the development and build phase, pulling images represents the deployment and runtime phase. This lesson focuses on consuming images from ECR, which mirrors exactly how AWS services like Amazon ECS and Amazon EKS retrieve and run your containerized applications in production environments.
The practical outcome you'll achieve in this lesson is pulling an image from your ECR repository and running it locally as a container. You'll master the key commands docker pull for retrieving images from ECR and docker run for starting containers from those images, completing the essential skills needed for working with container registries in production environments.
What You Need (Repo URI, Region, Permissions)
Before pulling images from ECR, you need to gather the same key information you used when pushing images in the previous lesson. This information ensures that your pull operations target the correct repository and region where your images are stored.
Your account ID remains the 12-digit number that uniquely identifies your AWS account and forms part of your ECR repository URI. Your region must match the region where your ECR repository exists, and this consistency is critical for both authentication and pull operations. Your repository URI combines these elements with your repository name to create the complete address that Docker uses to locate and pull your images.
As a reminder from the previous lesson, you can retrieve this information using the aws ecr describe-repositories command. This command displays your repository details, including the complete repository URI that follows the format {account-id}.dkr.ecr.{region}.amazonaws.com/{repository-name}. You'll use this exact URI format when pulling images, just as you did when pushing them.
The output shows your repository URI in the repositoryUri field, which you'll need for the pull operation. For example, if your account ID is 123456789012 and your repository is in us-east-1, your repository URI would be 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-web-app.
For pulling images from ECR, your AWS credentials need specific permissions that differ slightly from the push permissions you used previously. The essential permissions for pulling images are ecr:BatchGetImage and ecr:GetDownloadUrlForLayer. These permissions allow Docker to retrieve the image manifest and download the individual layers that make up your container image. You also need ecr:GetAuthorizationToken for authentication, which is the same permission required for pushing images.
Most AWS environments and IAM roles that have ECR access include these pull permissions by default, since pulling images is a common operation for deployment services like ECS and EKS. However, if you encounter permission errors during the pull process, these are the specific permissions to verify in your IAM policies or roles.
