Skip to content
Back to Cloud Services

AWS ECR: managed container registry for ECS/EKS

Store and deploy Docker images on AWS ECR with IAM auth, lifecycle policies, and cross-region replication.

Docker HostingIntermediate

Why

ECR integrates natively with ECS/EKS via IAM task execution roles — no separate registry credentials to rotate. Lifecycle policies auto-delete old images, and cross-region replication cuts pull latency for global deployments.

Docker is used by 59% of professional developers per the Stack Overflow 2024 survey. Docker Hub has 15M+ public images, and OCI image spec adoption means containers run identically across Docker, Podman, and containerd.

When

Use when running on ECS, EKS, or Fargate and you want IAM-based auth, or when you need cross-region replication for global pulls. Avoid Docker Desktop for production (license requires paid plan for 250+ employees) — use containerd or Podman.

Skip Docker for single-binary Go/Rust apps — a static binary + systemd is simpler.

How

1. Create a repo with `aws ecr create-repository --repository-name myapp`. 2. Login with `aws ecr get-login-password | docker login --username AWS --password-stdin <acct>.dkr.ecr.<region>.amazonaws.com`. 3. Tag `<acct>.dkr.ecr.<region>.amazonaws.com/myapp:tag`, push. 4. Add a lifecycle policy JSON to keep last 10 images. 5. For ECS, reference the image URI in the task definition; the task execution role needs ecr:GetDownloadUrlForLayer and ecr:BatchGetImage. 6. For cross-region, configure replication in the registry settings.

Example

# Login and push AWS_ACCT=123456789012; REGION=us-east-1 aws ecr get-login-password --region \${REGION} | \ docker login --username AWS --password-stdin \ \${AWS_ACCT}.dkr.ecr.\${REGION}.amazonaws.com docker push \${AWS_ACCT}.dkr.ecr.\${REGION}.amazonaws.com/myapp:1.0 # Lifecycle policy: keep 10 most recent, delete untagged after 1 day cat > lifecycle.json <<'EOF' { "rules": [{ "rulePriority": 1, "description": "keep 10", "selection": { "tagStatus": "any", "countType": "imageCountMoreThan", "countNumber": 10 }, "action": { "type": "expire" } }] } EOF aws ecr put-lifecycle-policy --repository-name myapp --lifecycle-policy-text file://lifecycle.json

Common Problems

  • ⚠ECR login tokens expire in 12h — CI pipelines fail mid-run; refresh in a step before each push.
  • ⚠Forgetting the lifecycle policy leads to $0.10/GB-month storage bloat from years of old images.
  • ⚠Cross-region replication doubles storage cost; only enable for regions with actual pull traffic.

Best Practices

  • ✓Always attach a lifecycle policy on creation — keep 10-20 tagged + expire untagged after 1 day.
  • ✓Use immutable tags (aws ecr put-image-tag-mutability --image-tag-mutability IMMUTABLE) to prevent overwrites.
  • ✓Scan on push with aws ecr put-image-scanning-configuration; fail CI on CRITICAL findings.

FAQ

What is AWS ECR: managed container registry for ECS/EKS and what problem does it solve?

Store and deploy Docker images on AWS ECR with IAM auth, lifecycle policies, and cross-region replication. It lets developers deploy, store, and scale without self-managing infrastructure — a core reference for cloud service selection.

How do I get started with AWS ECR: managed container registry for ECS/EKS in 5 minutes?

Two steps to run it: (1) Create a repo with `aws ecr create-repository --repository-name myapp`.; (2) Login with `aws ecr get-login-password | docker login --username AWS --password-stdin <acct>.dkr.ecr.<region>.amazonaws.com`.. Validate on the free tier first, then wire into production.

What is the #1 pitfall with AWS ECR: managed container registry for ECS/EKS?

The most frequent issue is: ECR login tokens expire in 12h — CI pipelines fail mid-run; refresh in a step before each push.. Run a pre-launch checklist item by item, and add policy/config scanning in CI.

What are the best practices for AWS ECR: managed container registry for ECS/EKS?

Best practices for AWS ECR: managed container registry for ECS/EKS include: Always attach a lifecycle policy on creation — keep 10-20 tagged + expire untagged after 1 day.; Use immutable tags (aws ecr put-image-tag-mutability --image-tag-mutability IMMUTABLE) to prevent overwrites.; Scan on push with aws ecr put-image-scanning-configuration; fail CI on CRITICAL findings.. The first one — "Always attach a lifecycle policy on creation — keep 10-20 tagged + expire untagged after 1 day." — should be a team default baked into your IaC templates.

How do I control cost and avoid bill surprises with AWS ECR: managed container registry for ECS/EKS?

Three ways to prevent overspend: (1) tag every resource with env/team and enable billing alarms; (2) set budget thresholds to trigger Slack/email alerts; (3) review idle resources in Cost Explorer regularly and clean them up. Most AWS ECR: managed container registry for ECS/EKS options offer a free tier — validate within free quota before scaling.