Docker Tags That Don't Move: Immutable Tags on AWS ECR
Mutable Docker tags let the same tag point to different images over time, which breaks rollbacks, security audits, and deployment consistency. This article shows how to fix that with ECR tag immutability, deliberate base image pinning, and a version-bump-driven CI/CD pipeline.
Two instances of your service are both running
myapp:v1.2.0 , and they're behaving differently. Your dashboards say they're identical. They aren't, because someone rebuilt the image after a hotfix and pushed it with the same tag. One instance pulled the old bits, one pulled the new ones, and the tag tells you nothing about which is which.This is the core problem with mutable image tags: a tag is just a pointer, and by default nothing stops that pointer from moving.
latest is the obvious offender, but any tag you allow to be overwritten has the same failure mode. The fix is to make your tags immutable, and on AWS this takes about thirty seconds of ECR configuration plus some discipline in your pipeline.What actually goes wrong
The hotfix example above is the mild version. The same root cause shows up in nastier forms:
Rollbacks that don't roll back.
If
v1.2.0 was overwritten, redeploying it doesn't get you back to what was running before. The original image may still exist as an untagged digest in the registry, but your deployment manifests reference tags, so your rollback path is gone.Security scans you can't trust.
A scanner flags CVEs in
myapp:v1.2.0 on Monday. On Wednesday the tag points at a different image and the scan comes back clean. Nothing was fixed; the evidence just moved. If you're subject to any kind of audit, this quietly breaks your trail from finding to remediation.Builds you can't reproduce.
FROM python:latest in a Dockerfile means every rebuild is a roll of the dice on the base layer. This one is upstream of your registry entirely, but it's the same problem.Two ways to pin an image
The only truly stable identifier for an image is its digest, the SHA256 of the manifest. You can reference images by digest directly:
123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp@sha256:a1b2c3d4...
This is immutable by construction, since the digest is derived from the content. The drawback is obvious: nobody looking at a task definition full of digests can tell you what version is deployed.
The practical alternative is registry-enforced tag immutability. Flip the setting on an ECR repository and any push that reuses an existing tag is rejected:
aws ecr put-image-tag-mutability \ --repository-name myapp \ --image-tag-mutability IMMUTABLE
Now
v1.2.4 behaves like a digest with a readable name. You keep semantic versioning for humans and get the same guarantee: that tag will point at one image, forever. GCR, ACR, and Docker Hub's paid tiers offer the equivalent, so nothing here locks you to AWS.A pipeline that makes this work
Immutability on the registry side only pays off if the rest of the pipeline cooperates. Here's a setup I've used for a Django app deployed to EKS, but it applies to anything containerized.
Pin the base image deliberately. The Dockerfile starts with:
FROM python:3.11-slim-bookworm
Each part of that tag is doing work.
3.11 gets you interpreter patch releases without a surprise jump to 3.12. slim keeps the attack surface small. bookworm pins the Debian release so an upstream move to Trixie can't break you. Rebuilding still pulls in security patches within those bounds, which is the balance you want: updates flow in, breaking changes don't.Tag from a version bump. The GitHub Actions workflow reads the app version from a git tag or VERSION file, builds the image, tags it
myapp:v1.2.4 , and pushes to ECR. The version bump is the trigger. If you need a rebuild just to pick up base image patches, you bump the patch version and say so in the commit message. Every artifact traces back to a commit.Let ECR reject mistakes. With immutability enabled, a workflow bug or a well-meaning manual push that reuses a tag fails loudly at push time instead of silently corrupting your deployment history.
Deploy by exact tag. The Kubernetes manifest (or ECS task definition) references the full immutable tag:
image: 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:v1.2.4
Now the chain is closed: what was built is what was scanned is what's running, and the tag in your manifest proves it.
If manual version bumps annoy you
The one real cost of this approach is that picking up base image patches requires a human to bump a version. Teams that rebuild frequently often add a timestamp to the tag instead, something like
v1.2.4-20260715T143000Z , and run a scheduled workflow that rebuilds nightly or weekly. Every build gets a unique tag automatically, and dependency updates land without anyone touching a VERSION file.The trade-offs are uglier tags, more artifacts to lifecycle out of your registry (ECR lifecycle policies handle this), and some communication overhead, since a new deployment with zero code changes tends to prompt "what changed?" questions.
The short version
Enable tag immutability on your ECR repositories. Pin base images to a minor version and OS release, not
latest . Cut a new version for every build, even dependency-only rebuilds. None of this is hard, and the payoff is that "what exactly is running in production?" becomes a question with one answer.Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article