Sub topic 6
Generating SBOM and provenance with docker buildx build
This chapter assumes you can write a Dockerfile, push an image to a registry, and read JSON with jq. You also need Docker Buildx and a registry you can push to. The examples use registry.example.com/demo/app, so replace it with your own repository.
What you are turning on
BuildKit can produce two attestations during a build. An attestation is a signed-ready statement about an image.
- The SBOM (Software Bill of Materials) lists the packages found in the image.
- The provenance describes how the image was built: source, builder, and parameters.
Neither is created by default for a plain local build. You request them with build flags, and BuildKit attaches the results to the image.
A small image to scan
Start with a Dockerfile that installs one package. The curl package will show up in the SBOM.
FROM alpine:3.20
RUN apk add --no-cache curl
CMD ["curl", "--version"]The shorthand flags
The shortest way to enable both attestations is --sbom and --provenance.
docker buildx build \
--sbom=true \
--provenance=mode=max \
--tag registry.example.com/demo/app:1.0 \
--push .--sbom=true runs the SBOM scanner. --provenance=mode=max records the most detailed provenance. The --push flag matters here, and the next sections explain why.
The --attest form
--attest is the long form. It names the attestation type and lets you set options on it.
docker buildx build \
--attest type=sbom \
--attest type=provenance,mode=min \
--tag registry.example.com/demo/app:1.0 \
--push .This build uses mode=min, which records less detail. Both forms produce the same kinds of attestation. Use whichever reads better in your scripts. Choosing between min and max is covered in a later chapter.
Why --push matters
Attestations are stored in the image index, next to the image manifests. A registry can hold an index, but the classic local image store usually cannot. If you build with the default Docker driver and load the result locally, the attestations are not kept. Pushing to a registry, or exporting with a driver that supports it, keeps them.
Checking that it worked
After the push, read the attestations back from the registry.
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .SBOM }}'
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .Provenance }}'For a readable package list, pipe the SBOM through jq.
docker buildx imagetools inspect registry.example.com/demo/app:1.0 \
--format '{{ json .SBOM }}' | jq .You should see curl and its dependencies among the packages. Inspection is covered in depth in a later chapter.
Turning provenance off
Provenance adds extra manifests to the index. Some registries and consumers cannot handle them. In that case, disable provenance for the build.
docker buildx build \
--provenance=false \
--tag demo/app:no-provenance \
--push .Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| No SBOM or provenance after a local build | Result loaded into the local image store | Push to a registry |
| Registry rejects the push or a tool fails on the image | The extra attestation manifests are not supported | Use `--provenance=false` or a registry that supports them |
| Only one flag seems to take effect | Mixing `--sbom` with a conflicting `--attest` value | Use one form per attestation type |
Exercise
You run docker buildx build --sbom=true --load -t demo/app:1.0 . and find no attestations on the result. Why, and what do you change?
Show answer
--load puts the image in the local image store, which does not keep the image index that holds attestations. Replace --load with --push to a registry, then run docker buildx imagetools inspect on the pushed tag.