What Are Docker Tags and Why Are They Important?
Table of Contents
A tag is a human-readable label pointing at a specific image inside a
repository, for example nginx:1.27, postgres:16-alpine or acme/api:1.4.0. The critical thing to internalize: a tag is a mutable pointer, not an identity. Two people pulling myapp:latest an hour apart can get two different images if someone pushed in between.
Tags are pointers, digests are identity #
In addition to a tag, every image also has a content-addressed digest (a SHA-256 hash of its manifest), which never changes for a given set of bytes:
docker pull nginx:1.27
#> 1.27: Pulling from library/nginx
#> Digest: sha256:6784fb0834aa7dbbe12e3d7471e69c290df3e6ba810dc38b34ae33d3c1c05f7d
#> Status: Image is up to date for nginx:1.27
#> docker.io/library/nginx:1.27
docker inspect --format='{{index .RepoDigests 0}}' nginx:1.27
#> nginx@sha256:6784fb0834aa7dbbe12e3d7471e69c290df3e6ba810dc38b34ae33d3c1c05f7d
Pushing a new image and reusing an existing tag just moves the pointer to a new digest; it doesn’t create a new tag or preserve the old one anywhere discoverable unless you tagged it separately first. This is exactly like a Git branch pointer versus a commit SHA: main moves, but the commit it pointed to yesterday still exists, you just need its hash to find it again.
Why the latest tag causes production incidents #
latest is not “the newest stable release”. It’s just the tag Docker applies by default when you don’t specify one. Nothing prevents it from pointing at a broken build. The common failure mode:
- CI builds and pushes
myapp:lateston every merge to main, including a broken one. - A production host restarts a container (crash, node replacement, autoscaling) and re-pulls
myapp:latest. - It gets the broken build, even though nobody intended to deploy it.
The fix is simple: never run latest in production. Pin a specific version tag or digest, and make deployments an explicit action that changes that pin, rather than something that happens implicitly on restart.
# Fragile: resolves to whatever `latest` currently points at
image: myapp:latest
# Stable only by convention (as long as nobody re-pushes 1.4.0)
image: myapp:1.4.0
# Guaranteed: a digest can never point at different bytes
image: myapp@sha256:2d194184b6e...
A tagging scheme that actually works #
A reasonable convention for most teams:
- Immutable release tags:
1.4.0, following semver. Never re-pushed once published. latest: still published, pointing at the newest stable release, purely as a convenience for localdocker runexperimentation, and never referenced in a deployment manifest.- Mutable dev/CI tags:
main,pr-482,sha-a1b2c3d. They are expected to change constantly, which is fine for CI and staging, but they are never promoted directly to production without a specific version tag. - Multi-part tags when you need to encode more than a version:
1.4.0-alpine,1.4.0-arm64(though multi-arch images usually handle architecture via manifest lists instead; see how registries work).
Deleting a tag doesn’t delete the image #
Untagging is cheap; it just removes a pointer. The underlying blobs stick around until a garbage-collection pass confirms nothing else references them, which is covered in more detail in the registries article. If you need an image gone for compliance reasons (it contained a leaked secret, for example), removing the tag is not enough: the image stays pullable by digest until its manifest is deleted and garbage collection has actually run. And if the registry was ever public, better treat the secret as compromised regardless.