Sub topic 5
What latest really means
This chapter assumes you can build and push images, know the registry/repository:tag reference form, and understand that a tag is a movable pointer to image content. If any of that is unfamiliar, review the earlier chapters on image references and tag mutability first.
latest is a default, not a promise
latest is an ordinary tag. Docker gives it special treatment in only one place: when a reference has no tag, Docker fills in latest.
docker pull nginx
# identical to:
docker pull docker.io/library/nginx:latestThe same default applies to docker run, docker build -t myapp (which tags the result myapp:latest), and FROM lines in a Dockerfile.
Docker does not check what latest points at. It does not mean the newest image, the most stable image, or the most recently pushed image. It means whatever the publisher last pushed under that name. A maintainer can push latest from an old branch, or never push it at all. In that case a pull of an untagged reference fails with a "manifest unknown" or "not found" error.
How latest moves
Because tags are mutable, latest moves each time someone pushes to it. Docker never moves it for you.
IMAGE=registry.example.com/team/myapp
docker build -t $IMAGE:1.4.2 .
docker tag $IMAGE:1.4.2 $IMAGE:latest
docker push $IMAGE:1.4.2
docker push $IMAGE:latestPushing 1.4.2 does not update latest. You must tag and push it yourself. If a release script forgets that step, latest stays on the previous version. If a hotfix for an old 1.3 line is pushed as latest, the tag goes backwards.
Why it is risky in production
Three problems follow from latest being a moving, unversioned name.
- No reproducibility. Two servers that pull
myapp:latestan hour apart can run different code. A rebuild of last month's deployment gives a different result. - No traceability. The name
latesttells you nothing about the version. Logs and incident reports that say "running latest" cannot be matched to a commit. - No clean rollback. Once
latesthas moved, the name no longer refers to the previous image. You need some other name or digest to go back to.
There is also a caching trap. Container hosts that already have a local image named myapp:latest may not pull again. Kubernetes, for example, defaults to imagePullPolicy: IfNotPresent for most tags, so one node can keep an old latest while another pulls a new one. Kubernetes uses Always as the default only when the tag is latest or absent, which hides the problem in some setups and surfaces it in others.
Where latest is still useful
latest is fine as a convenience pointer for people, not for systems that must be repeatable.
- Local experiments:
docker run --rm myappto try the current release. - Documentation quick starts that show the shortest working command.
- A development environment that should always track the newest release.
When you do publish it, make it a deliberate label. Apply it only to a stable release, and add it as an extra tag on an image that already has a version tag, so latest and 1.4.2 hold identical content.
IMAGE=registry.example.com/team/myapp
docker pull $IMAGE:latest
docker inspect --format '{{.Id}}' $IMAGE:latest
docker inspect --format '{{.Id}}' $IMAGE:1.4.2If both commands print the same ID, the two tags currently point at the same image. If they differ, latest has moved on or was never updated for this release.
Summary of behaviors
| Situation | What happens |
|---|---|
| Reference has no tag | Docker uses `latest` |
| You push `1.4.2` | `latest` does not change |
| You push `latest` from an old branch | `latest` points to older code |
| Nobody ever pushed `latest` | Untagged pulls fail |
Exercise
A teammate says "we deploy the newest build because our Compose file says image: team/myapp." Name two reasons this is unreliable, and give the fix.
Show answer
First, a reference without a tag means latest, and latest is only whatever was last pushed under that name, which may not be the newest build, or may not exist. Second, latest moves, so different hosts can run different code and you cannot trace or roll back to a known image. The fix is to reference an explicit version tag (such as team/myapp:1.4.2), a commit SHA tag, or a digest.
Exercise
You push the image tagged 1.5.0 but do not run any other tag or push command. What does myapp:latest point to afterward, and why?
Show answer
It still points to whatever it pointed to before, for example 1.4.2. Docker does not update latest automatically. You must run docker tag and docker push for latest yourself.