
The latest Tag Is Just a Name: Mutable Tags, Digests and Reproducible Deploys
- كاتب موثّق
محتويات المقال
latest. On Thursday, the autoscaler adds two servers. They start 1.3.1, while the older servers keep running 1.4.0. Nobody deployed anything, and the dashboards show the same image name everywhere.
The common misconception
latest always points to the newest version of an image, so deploying shop-api:latest means deploying the current release, and it's safe.
docker image tag reference says "If no tag is provided, Docker defaults to latest." And in a team where one pipeline builds one branch, the last image pushed usually is the newest, so most days the belief holds.
latest is the most recently pushed image with that name, by whoever pushed it. Being the newest version is a habit of some pipelines, not a rule of Docker or the registry.
What actually happens
A tag is a name that can move
shop-api:latest moves the name to the pushed image. Nothing compares version numbers or dates first. The same guide describes publishers moving tags like 3.21 to newer patch releases and adds that "most publishers use this tagging strategy, but it isn't enforced."
A digest is the image's fingerprint
docker image pull reference says that when pulling by digest, "you specify exactly which version of an image to pull."
Each machine resolves the tag when it pulls
docker run doesn't pull an image it already has: its default pull policy, missing, means "Pull the image if it was not found in the image cache, or use the cached image otherwise." A server that pulled latest last week keeps running last week's image. A new server pulls whatever latest is now. The Kubernetes docs warn about the result: "you might end up with a mix of Pods running the old and new code."
The fix: deploy the digest, not the name
registry:3.1.2 on port 5055. Version 1.4.0 was pushed as 1.4.0 and latest; then the 1.3 hotfix was pushed as 1.3.1 and, like in the hook, as latest. To play a server that had pulled latest before the hotfix, we pointed its local latest tag back at 1.4.0:
# The 1.3 hotfix pipeline also moves latestdocker tag localhost:5055/shop-api:1.3.1 localhost:5055/shop-api:latestdocker push localhost:5055/shop-api:latest# latest: digest: sha256:fdcd194b8298db4352335e4833b2febb6af2cff72f71341a0ff369b15897dc54 size: 668# A server that pulled latest before that pushdocker run --rm localhost:5055/shop-api:latest# shop-api 1.4.0# A server that pulls nowdocker run --rm --pull=always localhost:5055/shop-api:latest# shop-api 1.3.1# Keep the digest that the release push printsdocker push localhost:5055/shop-api:1.4.0# 1.4.0: digest: sha256:f2437627542a2ecd3ea208d26ec8b508b7753ceb12ea39a2863f37c37a977c97 size: 668# Deploy exactly that image on every serverDIGEST=sha256:f2437627542a2ecd3ea208d26ec8b508b7753ceb12ea39a2863f37c37a977c97docker pull "localhost:5055/shop-api@$DIGEST"# Digest: sha256:f2437627542a2ecd3ea208d26ec8b508b7753ceb12ea39a2863f37c37a977c97docker run --rm "localhost:5055/shop-api@$DIGEST"# shop-api 1.4.0latest from 1.4.0's digest to 1.3.1's: the newest push, not the newest version. The server with a cached copy ran 1.4.0 without asking the registry, and the server that pulled got 1.3.1. In the second tab, the pull ran on a machine with no copy of the image, after latest had already moved. It still got 1.4.0, because the digest names the content, and that content can't change.
shop-api (no tag) | shop-api:latest | |
shop-api:latest | ||
shop-api:1.4.0 | ||
shop-api@sha256:f243… | ||
shop-api:1.4.0@sha256:f243… |
How to apply it in your project
Stop deploying latest Search your deploy scripts, Compose files and manifests for :latestand for images with no tag at all. The Kubernetes docs say to avoid it in production because "it is harder to track which version of the image is running and more difficult to roll back properly."Tag every build with something unique Use the release version or the commit SHA, and never push the same tag twice. Treat a reused tag as a bug in the pipeline. Record the digest and deploy it Save the digest that docker pushprints with the build, and passimage@digestto the deploy step. A rollback then means deploying the previous digest, which still points at exactly what ran before.Pin base images too Write FROMlines astag@digestand let a bot open pull requests when the publisher moves the tag. Your builds stop changing under you, and the updates stay visible.
Key takeaways
latestis the default tag name, not a version: it points to whatever was last pushed with that name.Tags are mutable; a digest is the hash of the image's content and can't move. Each machine resolves a tag when it pulls, and docker runreuses a cached image by default, so one tag can mean different images on different servers.Deploy by digest, ideally written as tag@digest, and roll back to the previous digest.Pinned digests skip security updates, so update them on purpose through your pipeline.
التعليقات (0)