Sub topic 8
Docker Hardened Images: minimal, maintained, and attested
This chapter assumes you can read a Dockerfile and use multi-stage builds. It also assumes you know what distroless images leave out. The goal is to explain what Docker Hardened Images (DHI) add and when they are the right choice.
What a hardened image is
A Docker Hardened Image is a base image that Docker builds and maintains from a curated catalog. It is used like any other base image, in a FROM line. Three properties set it apart from a plain community image:
- Minimal. Runtime variants contain only what the application needs. They typically have no shell and no package manager, which is the same idea as distroless.
- Maintained. The publisher rebuilds images when upstream packages get security fixes. A commercial offering adds support commitments for fix timelines. Check the current terms for your tier.
- Attested. Each image ships with signed metadata about how it was built and what it contains.
Distroless is a design style, and Google's distroless images are one well-known implementation. DHI is a product with a maintenance process around it.
What "attested" means
An attestation is a signed statement about an image. You can check it before you deploy. A hardened image typically carries these:
| Attestation | What it tells you |
|---|---|
| SBOM (software bill of materials) | The packages and libraries inside the image |
| Provenance | Where, when, and from which source the image was built |
| VEX (vulnerability exploitability exchange) | Which known CVEs do not actually affect the image |
| Signature | That the image came from the publisher and was not altered |
VEX data matters for scanning. A scanner that reads it can suppress findings the publisher has judged non-exploitable. This gives you a shorter, more useful report than a raw CVE list.
Using a hardened image
The pattern is the same as in the distroless chapter. You build in a full toolchain image and copy the result into the hardened runtime image. Look up the real registry, image name, and tag in the catalog. The placeholders below are not valid values.
# Replace the placeholders with an image and tag from the Docker Hardened Images catalog
FROM <registry>/<hardened-image>:<tag>@sha256:<digest>
COPY --from=build /out/app /app
ENTRYPOINT ["/app"]Adding @sha256:<digest> pins the exact image content. A tag can move, but a digest cannot. The pinning chapter covers this in more detail.
flowchart LRThe build flow is easier to see in a diagram.
Development and runtime variants
Hardened catalogs usually offer two kinds of image for the same runtime. The runtime variant has no shell. A development variant adds a shell and a package manager so you can build and debug. Use the development variant in your build stage and the runtime variant in the final stage. Do not ship the development variant to production, because it brings back the attack surface you were trying to remove.
Checking what you built
After you build, compare the image against your previous base. These commands list the sizes, then scan the image and print its package list:
docker image ls
docker scout cves myapp:latest
docker scout sbom myapp:latestIf the scan shows far fewer findings than your old base image, that is the main benefit you are paying for. If it shows the same findings, check whether they come from your own application dependencies. A hardened base cannot fix vulnerable libraries that you installed yourself.
Trade-offs and common errors
- No shell.
docker exec -it app shfails on a runtime variant. Use the debugging techniques from the previous chapter, or temporarily switch to a development variant in a non-production build. - Fewer packages. If your app needs a system library that the image lacks, you must add it in the build stage and copy it over. You cannot run
apt-getin the final stage. - Catalog limits. You can only use the runtimes, versions, and tags the catalog provides. An unusual language version may not be available.
- Licensing and access. Registry access, available tags, and support terms depend on the plan you use. Confirm them before you standardize on it.
- A false sense of safety. The base image is only part of your risk. Your application code and dependencies still need scanning.
Exercise
Your Go service builds fine, but after you move the final stage to a hardened runtime image, docker exec -it app sh fails. Is this a bug, and what are two ways to investigate the container?
Show answer
It is expected. Runtime variants of hardened images have no shell. You can investigate by building a temporary image from the development variant, which includes a shell, or by using other debugging methods such as logs and a separate debug container attached to the same process namespace. Do not ship the development variant to production.