Skip to content
intermediate Phase 9 · Docker CI/CD Integration

Push & Pull Automation

Automate image push to registries with versioning and tagging strategies.

45m
0 problems
Topic Progress 0%

Tagging Strategy

Tagging Strategy

Tags are mutable pointers, so give each one a defined role:

Tag Meaning Audience
1.4.2 immutable release deployments
sha-4f9c2ab exact commit build debugging, rollback
latest most recent default-branch build humans only
1.4, stable moving channels conservative rollouts

Push by digest after building, then add tags:

DIGEST=$(docker push registry.example.com/app:sha-4f9c2ab | tail -1)
docker tag app:local registry.example.com/app:1.4.2
docker push registry.example.com/app:1.4.2

One image ID can carry many tags; the registry stores the manifest once.

Authenticating Across Registries

Authenticating Across Registries

Each registry wants its own credential flow:

# Docker Hub
docker login -u $DH_USER

# ECR: token expires in 12 hours
aws ecr get-login-password --region us-east-1 |   docker login --username AWS --password-stdin 123.dkr.ecr.us-east-1.amazonaws.com

# GHCR: GitHub token with write:packages
echo $GITHUB_TOKEN | docker login ghcr.io -u USER --password-stdin

For multi-registry release, push the same manifest to each target rather than rebuilding: docker buildx imagetools create -t reg2/app:1.4.2 reg1/app:1.4.2 copies references without pulling layers. Always use --password-stdin so the token never lands in shell history or process lists.

Lifecycle, Signing, and Pitfalls

Lifecycle, Signing, and Pitfalls

Unbounded growth. Every CI push adds manifests; configure an ECR lifecycle policy (keep the last 30 images) or enable GHCR package cleanup so old tags are pruned automatically.

Mutable tags betray rollback. If latest moves while a deploy references it, yesterday's container may restart on today's code — deployments pin digests (app@sha256:...).

Provenance. Sign releases with cosign sign registry.example.com/app:1.4.2 and verify in admission control; an unsigned tag proves nothing about origin.

Interview: explain tag mutability, walk an ECR auth flow including token expiry, and describe how digest pinning makes rollback deterministic.

Quiz

1. Why should production deploys reference a digest instead of a tag?

Question 1 options

2. How does an ECR login token differ from Docker Hub's?

Question 2 options

3. What problem do registry lifecycle policies solve?

Question 3 options

Flashcards

Question

Tag mutability

Answer

Tags can be moved; only digests are fixed, which is why releases pin sha256.

Question

ECR auth

Answer

aws ecr get-login-password | docker login --password-stdin; token valid 12 hours.

Question

imagetools create

Answer

Copies a manifest to another tag or registry without rebuilding or pulling layers.

Question

Lifecycle policy

Answer

Registry rule expiring old/untagged images so storage does not grow forever.

Question

cosign

Answer

Signs image digests so consumers can verify provenance before pulling.

Revision Notes

Key Takeaways

  • 1. Give every tag a role; let automation use SHA or digest, humans use semver
  • 2. Push with --password-stdin and expect ECR tokens to expire
  • 3. Prune old images and sign the ones you keep

Interview Tips

  • • Explain why 'latest worked yesterday' is a rollback failure and how you prevent it
  • • Walk the ECR credential flow and where it belongs in CI

Cheat Sheet

semver + sha tags, latest for humans; deploy by digest; ECR token via get-login-password (12h); imagetools create for multi-registry; cosign sign releases.

Continue Learning