In this lesson, you will learn how to achieve bulletproof deployment stability by moving beyond mutable tags and embracing immutable image digests.
The Problem with Mutable Tags
In previous lessons, we discussed semantic versioning (like v1.2.0). While these tags are easy for humans to read, they are mutable. This means a developer can overwrite an existing tag by pushing a new build to the same name.
If your Kubernetes cluster pulls myapp:latest or even myapp:v1.2.0 at two different times, you might end up running two different versions of your application code because the tag was updated on the registry in the interim. This "tag drifting" can lead to inconsistent behavior in production that is notoriously difficult to debug.
The Immutable Solution: Digests
To guarantee that you are running the exact same binary every single time, you should use a Content Addressable Digest. A digest is a unique, unchangeable hash (like sha256:a1b2c3d4...) calculated from the image’s contents. Even if someone re-pushes the same tag, the digest will change if the underlying code changes.
When you deploy to Kubernetes, you can reference the image by its digest to ensure the cluster never downloads a "surprise" version:
spec:
containers:
- name: my-app
# Using the digest ensures strict immutability
image: myregistry.com/my-app@sha256:7b5d...e2f1
Implementing the Workflow
- Build and Tag: Continue using your standard semantic tags for human readability and CI/CD tracking.
- Resolve the Digest: After pushing your image, use
docker inspector your registry's API to capture the digest associated with that specific build. - Deploy: Update your Kubernetes manifests or CI/CD deployment scripts to use the resolved digest.
By pinning your deployments to a specific digest, you create an immutable link between your build pipeline and your infrastructure. You no longer have to worry about whether a tag has been "re-pointed"—the digest guarantees bit-for-bit consistency across every environment, from staging to production.
Key Takeaway: Replace mutable image tags with unique, content-addressable digests in your deployment manifests to ensure that the code you tested is exactly the code you run in production.