Opscraft
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 diagramCI pipelineOIDC role, no storedkeysAmazon ECRimmutable tags,scanningEKS nodenode role: read-onlypullpushpullPrivate subnets need VPC endpoints for ecr.api, ecr.dkr and an S3 gateway endpoint (layers live in S3), or a NATgateway.
Figure 1. Pushing to Amazon ECR and pulling on EKS, with no long-lived keys anywhere.
Swipe sideways to see all of it, or tap to open it full screen.

Repository settings to mention

  • Tag immutability — prevents overwriting 1.4.2 with 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:BatchGetImage and ecr: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.dkr and 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 diagramone imagesha256:9f86…3f9c2a1deploy this1.4.2release namemainmoves: never deploy by itGitOpscommits the new SHAtag
Figure 2. Tag every image with its Git SHA and deploy that; add semver for releases. Branch tags are conveniences that move.
Swipe sideways to see all of it, or tap to open it full screen.