You already know how to create Docker images (subchapter 17.1). Now a practical question arises: once you’ve built your image, where do you store it so your AWS servers or services can use it? The answer is an image registry, and AWS’s is called ECR (Elastic Container Registry).

The problem: images need to be stored somewhere

You build an image on your computer. But to deploy it on AWS (in ECS or EKS, which we’ll see next), those services need to download it from somewhere accessible. You can’t run an image that’s only on your laptop; it has to be in a central place that everyone can pull from.

Your computer          ???            AWS servers
  you build ──────► (where?) ────► download and run
  the image          you store       the image

That “central place” is an image registry.

What is an image registry

A container registry is a storage for Docker images. You upload (push) your images to it, and then any authorized machine or service downloads (pull) them to run.

   You push           Registry            They pull
   your image   ─────► [images] ◄──────── ECS / EKS / servers

You probably know Docker Hub, the most famous public registry. ECR is AWS’s equivalent, designed for your private images.

Analogy: an image registry is like a warehouse or template library. You store your “molds” there (images, remember the analogy from subchapter 17.1), labeled and organized, and anyone with permission can go get the mold they need to make their cookies (containers).

What is ECR

ECR (Elastic Container Registry) is AWS’s private, managed image registry. Its key features:

Private and secure

Your images are private by default: only those you authorize (via IAM, Chapter 7) can upload or download them. This is important because your images contain your code and intellectual property; you don’t want them exposed to the world.

Integrated with IAM

Access control uses IAM (Chapter 7), just like the rest of AWS. You define with policies who can push (upload) and who can pull (download). Apply the least privilege principle (subchapter 7.2): for example, the CI/CD system can upload images and ECS can only download them.

Integrated with ECS and EKS

ECR connects naturally with the services that run containers in AWS (ECS and EKS, next subchapters). When you deploy an application, those services download the image directly from ECR, with no complicated setup and within the AWS network (fast and secure).

Managed

Like other managed services we’ve seen, AWS takes care of the infrastructure: availability, storage scaling, etc. You just upload and download images.

The workflow with ECR

The typical cycle, connecting development with deployment:

1. Build the image           → docker build (subchap. 17.1)
2. Tag it for ECR            → with your ECR repository address
3. Authenticate to ECR       → with your AWS (IAM) credentials
4. Push the image            → it’s stored in ECR
5. ECS/EKS pulls it          → and runs your containers

Real-world example: a team develops an API. Their CI/CD system (Chapter 22), every time a change is approved, builds a new image of the API and uploads it to ECR with a version tag (e.g. api:v2.3). Then, ECS downloads that version from ECR and deploys it. ECR is the “bridge” between the code that’s built and the containers that are run.

Repositories and tags

Within ECR, you organize images into repositories (usually one per application) and each image has a tag that usually indicates the version:

Repository "my-api"
 ├── my-api:v1.0    (version 1.0)
 ├── my-api:v2.0    (version 2.0)
 └── my-api:latest  (the most recent)

Tags let you have multiple versions of the same application and choose which one to deploy. This is key to being able to roll back to a previous version quickly if a new one causes problems (rollback).

Cost note: ECR charges for image storage. Old images you no longer use accumulate, so it’s a good idea to set up lifecycle policies (similar to those in S3, subchapter 5.3) that automatically delete old versions and keep costs under control.

What you should remember

  • A built image must be stored in a registry so AWS services can download and run it; it’s not enough to have it on your laptop.
  • ECR (Elastic Container Registry) is AWS’s private, managed image registry (the private equivalent of Docker Hub).
  • It’s private and secure (access control with IAM, least privilege) and integrated naturally with ECS and EKS, which download images from there.
  • Workflow: you build the image → upload it (push) to ECR → ECS/EKS downloads it (pull) and runs it. It’s the “bridge” between development and deployment.
  • You organize images in repositories with version tags, which lets you deploy specific versions and do rollbacks. Use lifecycle policies to delete old images and control costs.

In the next subchapter we’ll look at the service that runs your containers: ECS, with its task definitions, services, and the difference between Fargate and EC2.

Cloud, AWS & Terraform — From Zero to Expert

Chapter 1 · What is cloud computing

Chapter 2 · The cloud market and major providers

Chapter 3 · Regions, availability zones and edge

Chapter 4 · Compute: EC2

Chapter 5 · Storage: S3

Chapter 6 · Networking: VPC

Chapter 7 · Identity and access: IAM

Chapter 8 · Managed databases

Chapter 9 · Why Infrastructure as Code

Chapter 10 · HCL: the Terraform language

Chapter 11 · Providers and state

Chapter 12 · Your first real infrastructure in Terraform

Chapter 13 · Load balancing and auto scaling

Chapter 14 · Serverless with Lambda

Chapter 15 · Messaging and events

Chapter 16 · Content delivery and DNS

Chapter 17 · Containers on AWS

Chapter 18 · Modules: reuse and composition

Chapter 19 · Workspaces and environment management

Chapter 20 · Remote backends and locking

Chapter 21 · Infrastructure testing

Chapter 22 · Terraform in CI/CD

Chapter 23 · Defense in depth

Chapter 24 · Observability: logs, metrics and traces

Chapter 25 · Cost optimization

Chapter 26 · High availability and disaster recovery

Chapter 27 · AWS Well-Architected Framework

Chapter 28 · Serverless architectures at scale

Chapter 29 · Data platforms on AWS

Chapter 30 · Multi-account and landing zones

Chapter 31 · Platform Engineering and Internal Developer Platform

Chapter 32 · Relevant AWS certifications

Chapter 33 · Projects to consolidate what you've learned

Chapter 34 · Resources and community

© Copyright 2024. All rights reserved