Docker · Lesson 9 of 11 · 3 min read
ECR and registry operations
Pushing to ECR
aws ecr get-login-password --region ap-south-1 \
| docker login --username AWS --password-stdin 123456789012.dkr.ecr.ap-south-1.amazonaws.com
docker tag orders:local 123456789012.dkr.ecr.ap-south-1.amazonaws.com/orders:3f9c2a1
docker push 123456789012.dkr.ecr.ap-south-1.amazonaws.com/orders:3f9c2a1
The login token is valid for 12 hours. In CI, assume an IAM role via OIDC (GitHub Actions/Jenkins) rather than static keys; on EKS, nodes pull using the node role's AmazonEC2ContainerRegistryReadOnly permissions.
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
Repository settings to mention
- Tag immutability — prevents overwriting
1.4.2with different content. Strongly recommended for release tags. - Lifecycle policies — expire untagged images after N days and keep only the last N tagged images, controlling storage cost.
- Scan on push — basic scanning (AWS-native; the older Clair-based engine has been retired) or enhanced scanning (Amazon Inspector, with continuous re-scanning when new CVEs appear).
- Encryption — AES-256 by default or KMS.
- Cross-account access — repository policies grant other accounts' roles
ecr:BatchGetImageandecr:GetDownloadUrlForLayer. - Replication — cross-region/cross-account replication for DR and lower pull latency.
- Pull-through cache — cache Docker Hub/Quay/GHCR images in ECR to avoid rate limits and external dependency.
- Private networking — nodes in private subnets need VPC endpoints for
ecr.api,ecr.dkrand an S3 gateway endpoint (layers are stored in S3), or a NAT gateway.
Tagging strategy
| Tag | Purpose |
|---|---|
Git SHA (3f9c2a1) |
Immutable, traceable; what deployments reference |
Semver (1.4.2) |
Human-friendly releases |
Branch/env (main, staging) |
Convenience only — mutable, never deploy by them |
buildcache |
BuildKit registry cache |
GitOps tools (for example Flux image automation) can watch ECR and commit new SHA or semver tags into the config repository automatically.
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.