Sub topic 6
Tags versus digests
This chapter assumes you can build and push an image to ECR, as covered in the previous chapter. It also assumes you know what a manifest and a layer are. Here you learn how a tag differs from a digest, how to read both from ECR, and which one to use in deployments.
Two ways to name the same image
An image in ECR can be referred to in two ways.
- A tag is a human-readable label, such as
1.0.0orlatest. A tag is a pointer. It refers to one image at a time, and it can be moved to a different image. - A digest is a SHA-256 hash of the image manifest, written as
sha256:followed by 64 hexadecimal characters. A digest is computed from the content, so it cannot be moved. If the manifest changes in any way, the digest changes.
An image can have zero, one, or many tags. It always has exactly one digest. The repository stores the manifest and layers once, and tags are just names attached to that manifest.
Referencing an image
The two forms look different in the image URI.
| Form | Example | Meaning |
|---|---|---|
| Tag | `123456789012.dkr.ecr.us-east-1.amazonaws.com/my-app:1.0.0` | Whatever image the tag points to right now |
| Digest | `123456789012.dkr.ecr.us-east-1.amazonaws.com/my-app@sha256:<digest>` | Exactly the content with that hash |
Note the separator. A tag follows a colon (:). A digest follows an at sign (@). If you write both, as in my-app:1.0.0@sha256:<digest>, Docker uses the digest and ignores the tag.
Reading tags and digests from ECR
The describe-images command lists what the repository holds. This query returns the tags, digest, and push time for each image.
aws ecr describe-images \
--repository-name my-app \
--region us-east-1 \
--query 'imageDetails[].{tags:imageTags,digest:imageDigest,pushed:imagePushedAt}'
docker pull 123456789012.dkr.ecr.us-east-1.amazonaws.com/my-app@sha256:<digest>Replace <digest> with a value from the listing. The output looks like this:
[
{
"tags": ["1.0.0", "stable"],
"digest": "sha256:3f1c...e9a2",
"pushed": "2026-11-20T09:14:02.511000+00:00"
},
{
"tags": null,
"digest": "sha256:77b0...41cd",
"pushed": "2026-11-18T16:40:55.120000+00:00"
}
]The second entry has tags: null. That image is untagged. It still exists and can still be pulled by digest. You will meet untagged images often, and the reason is covered next.
How an image becomes untagged
When you push a tag that already exists, ECR moves the tag to the new image. The old image loses that tag. If it had no other tags, it becomes untagged but stays in the repository and keeps costing storage.
Consider this sequence:
- You push
my-app:latest. The image has digestsha256:aaa.... - You rebuild and push
my-app:latestagain. The image has digestsha256:bbb.... - The tag
latestnow points tobbb. The imageaaais untagged.
Anyone who pulls my-app:latest after step 2 gets different content than before. Nothing in the pull command changed. This is the main risk of deploying by mutable tag.
Why digests give reproducible deployments
A deployment is reproducible if running it twice gives the same software. Consider what can go wrong with tags:
- A task restarts and pulls
latest, but someone pushed a newlatestin between. Two copies of your service now run different code. - You roll back by redeploying the old tag, but the tag was moved, so you get the new code again.
- During an incident you cannot tell which build was running, because the tag name no longer identifies it.
A digest removes these problems. A pull by digest returns the same bytes every time. Docker also verifies the downloaded content against the hash, so a corrupted or tampered manifest is rejected.
Digests have costs too:
- They are not readable.
sha256:3f1c...tells you nothing about the version. - You must obtain the digest after the push, because it is not known until the image is built and uploaded.
- Digest pinning means you must update the reference on every release. That update is usually automated in a pipeline.
A common pattern combines both. Use tags for people and for discovery, and use digests for what actually runs.
Getting the digest in a pipeline
After docker push, Docker prints the digest. In automation, query ECR for it by tag rather than parsing Docker's output:
DIGEST=$(aws ecr describe-images \
--repository-name my-app \
--image-ids imageTag=1.0.0 \
--region us-east-1 \
--query 'imageDetails[0].imageDigest' \
--output text)
echo "123456789012.dkr.ecr.us-east-1.amazonaws.com/my-app@${DIGEST}"The printed URI is what you place in a task definition, a Kubernetes manifest, or a deployment parameter.
Do the lookup right after the push, in the same pipeline run. If another run moves the tag between your push and your query, you will capture the wrong digest. Immutable tags (next chapter) remove that race.
Multi-architecture images
Be careful with digests when you build for more than one CPU architecture. A multi-architecture image is published as a manifest list (also called an image index). The tag points to the list, and the list points to one manifest per platform, such as linux/amd64 and linux/arm64.
This gives you two kinds of digest:
- The digest of the manifest list. Pulling by it lets Docker choose the right platform for the host.
- The digest of a single platform manifest. Pulling by it always gives that one architecture.
For portable deployments, pin the manifest list digest. For debugging a platform-specific problem, pin the platform manifest digest. describe-images reports the list's imageManifestMediaType, which tells you which kind you are looking at.
Common mistakes
- Deploying
latestto production.latestis only a tag with a conventional name. Docker adds it when you omit a tag, and it does not mean "newest" to ECR. - Assuming a tag is a version. A mutable tag such as
1.0can be overwritten by a rebuild. Unless the repository enforces immutability, the tag is only a promise. - Deleting an image by tag and expecting only the tag to go. With
batch-delete-image, usingimageTagon an image that has several tags removes only that tag. If it is the last tag, the image is deleted. UsingimageDigestdeletes the image and all of its tags. - Comparing digests across local and remote images carelessly. The local image ID shown by
docker imagesis a different hash (of the image configuration) from the registry digest. Usedocker images --digeststo see the registry digest after a push or pull.
Summary of when to use each
| Situation | Prefer |
|---|---|
| Local development and quick tests | Tag |
| Naming releases for people (`1.4.2`, `2026-11-26`) | Tag |
| Production task definitions and Kubernetes manifests | Digest |
| Rollbacks and audits | Digest |
| Security scanning results tied to a specific build | Digest |
Exercise
You pushed my-app:latest on Monday and again on Tuesday with a new build. On Wednesday, a node restarts and pulls my-app:latest. Which image does it get, what happened to Monday's image, and how would you have guaranteed the node ran Monday's build?
Show answer
The node gets Tuesday's image, because the tag latest moved to it when you pushed. Monday's image still exists in the repository but is now untagged, and it keeps using storage until a lifecycle policy removes it. To guarantee Monday's build, reference it by digest (my-app@sha256:<digest>), which you can read with aws ecr describe-images. The digest never moves.
Exercise
A teammate writes the pull reference my-app:1.0.0@sha256:<digest>. The tag 1.0.0 currently points to a different image than that digest. Which image does Docker pull?
Show answer
The image with the given digest. When both a tag and a digest are present, the digest decides which content is pulled, and the tag is ignored.