Tags & Versions
Tags are how you name image versions. nginx:1.27, myapp:v2.4.1, myapp:sha-abc123. The dangerous default is :latest — it’s ambiguous and bites in production.
Tagging strategy that scales
EXAMPLE
# 1) Local tag on build
docker build -t myapp:1.4.2 .
docker build -t myapp:1.4.2 -t myapp:1.4 -t myapp:latest .
# 2) Push to a registry
docker tag myapp:1.4.2 ghcr.io/me/myapp:1.4.2
docker push ghcr.io/me/myapp:1.4.2
# 3) Multi-tag in one push (recent Docker / buildx)
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t ghcr.io/me/myapp:1.4.2 \
-t ghcr.io/me/myapp:1.4 \
-t ghcr.io/me/myapp:latest \
-t ghcr.io/me/myapp:sha-$(git rev-parse --short HEAD) \
--push .
# 4) Production: pin by DIGEST, not tag — immutable
docker pull ghcr.io/me/myapp@sha256:9f2a3...
# k8s deployment YAML
# image: ghcr.io/me/myapp@sha256:9f2a3...
# 5) Inspect tags + digests
docker images --digests | head
docker manifest inspect ghcr.io/me/myapp:1.4.2
# 6) Don't deploy :latest to production
# • :latest moves under your feet (someone else's push retags it)
# • rollbacks become guesswork
# • container restarts can pull a new image silently
# Better defaults:
# • semver: 1.4.2, 1.4, 1
# • commit SHA: sha-abc1234
# • date-based: 2026-06-07
# • environment: prod, staging (mutable, points at an immutable tag)
# 7) Re-tagging strategy for environments
docker tag ghcr.io/me/myapp:1.4.2 ghcr.io/me/myapp:staging
docker push ghcr.io/me/myapp:staging
# Promote to prod after smoke tests
docker tag ghcr.io/me/myapp:1.4.2 ghcr.io/me/myapp:prod
docker push ghcr.io/me/myapp:prod
# 8) Garbage-collect old tags (registries have their own UIs/APIs)
# GHCR: gh api -X DELETE /user/packages/container/myapp/versions/<id>
# Quay/ECR/Harbor: per-registry retention policies
Why it matters
Always pin production deploys to a content-addressable digest (@sha256:...). Tags can be re-pushed; digests can’t. The 3am rollback is suddenly trivial.
Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.
Example
Example
docker tag my-api:1.0 ghcr.io/user/my-api:1.0 docker tag my-api:1.0 ghcr.io/user/my-api:latestTry it Yourself »
Discussion
Loading…