Sub topic 12
Pinning a Container Base Image by Digest
This chapter assumes you know basic Docker commands and have seen a Dockerfile. It focuses on how to make the operating-system layer of an ML environment reproducible.
Tags are names, not permanent versions
A Docker image reference such as python:3.11-slim uses a tag. A tag is a movable name chosen by the image publisher. The publisher can update that name to point to a newer image without changing your Dockerfile.
That update can change:
- System libraries such as
glibcand OpenSSL - Installed operating-system packages
- Python patch versions
- CPU architecture contents
- Security fixes and behavior of native ML dependencies
A digest is a cryptographic identifier for one exact image manifest. It is written after @sha256::
FROM python:3.11-slim@sha256:<image-digest>The placeholder is not usable as written. Replace it with the digest published for the exact image you have tested.
| Reference | What it identifies | Reproducibility |
|---|---|---|
| `python:3.11-slim` | A publisher-controlled tag | Weak |
| `python:3.11-slim@sha256:abc...` | One exact image manifest | Stronger |
How a digest fixes the image
When Docker pulls a digest-pinned reference, it verifies that the downloaded manifest matches the requested digest. If the registry tag later moves, this reference still selects the original manifest.
The digest may identify a multi-platform manifest. Docker then selects the platform-specific image for the host, such as linux/amd64 or linux/arm64. For strict cross-platform reproducibility, pin and build for an explicit platform, or record the platform-specific digest as part of the build metadata.
Choosing and updating a digest
First choose a tag that matches your supported Python version and platform. Build and test the image. Then record the digest returned by the registry or your image inspection tooling.
Treat digest updates as dependency updates:
- Select a newer trusted base-image tag or digest.
- Build the complete ML image from scratch.
- Run tests and a small training or inference check.
- Review operating-system and Python changes.
- Commit the new digest separately from application changes.
- Keep the previous digest available for rollback.
Pinning does not make an image safe or current. It makes the chosen image stable and reviewable. You still need a planned process for security updates.
Exercise
Why is python:3.11-slim@sha256:... more reproducible than python:3.11-slim, and what must you do when security fixes are released?
Show answer
The digest identifies one exact image manifest, while the tag can move. Test and review a newer image, then update the committed digest through a controlled dependency update.