Containers and Kubernetes · Intermediate · 16 min
Generate an SBOM for a container image with Syft
By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · Syft 1.57.2
You will install Syft 1.57, write SPDX and CycloneDX SBOMs for a registry image and a source folder, query their packages and licences with jq, diff two image versions and file the results by image digest.
On this page
A software bill of materials (SBOM) is a machine-readable list of what is inside a piece of software: every package, its version, a package URL (purl) that names it unambiguously, and the licence it declares. For a container image that means the OS packages from the base image plus the libraries your app brought in. When a new vulnerability is announced, the SBOM tells you in seconds which of your images contain the affected package, without pulling and unpacking each one again.
More people now ask for one. The EU Cyber Resilience Act (Regulation (EU) 2024/2847) requires manufacturers of products with digital elements sold in the EU to draw up an SBOM "in a commonly used and machine-readable format" covering at least the top-level dependencies. Its vulnerability reporting duties apply from 11 September 2026 and the rest of the regulation from 11 December 2027. Public-sector buyers ask too: in the US, OMB memo M-26-05 (January 2026) withdrew the single federal attestation form but leaves each agency free to require an SBOM from its suppliers. Procurement teams elsewhere, including banks and telecoms in Africa that buy software from abroad, increasingly add the same clause to contracts.
Syft, from Anchore, is an open-source command-line tool that writes SBOMs. It reads an image straight from a registry, so it does not need Docker installed. In this tutorial you will write SBOMs for two versions of the Alpine image and for a small Python project, compare the SPDX and CycloneDX formats, pull package and licence lists out of them with jq, see exactly what changed between two image versions, and keep the files in a layout that ties each SBOM to an image digest.
Everything happens in ~/sbom-demo, which you delete at the end.
Step 1 · Install Syft and jq
Syft ships as a single binary on its GitHub releases page, with a checksums file next to it. This tutorial uses Syft 1.57.2, the current release at the time of writing. dpkg --print-architecture prints amd64 or arm64, which matches the release file names.
sudo apt update
sudo apt install -y curl ca-certificates jq
mkdir -p ~/sbom-demo && cd ~/sbom-demo
SYFT_VERSION=1.57.2
ARCH="$(dpkg --print-architecture)"
curl -fsSLO "https://github.com/anchore/syft/releases/download/v${SYFT_VERSION}/syft_${SYFT_VERSION}_linux_${ARCH}.tar.gz"
curl -fsSLO "https://github.com/anchore/syft/releases/download/v${SYFT_VERSION}/syft_${SYFT_VERSION}_checksums.txt"
sha256sum --ignore-missing -c "syft_${SYFT_VERSION}_checksums.txt"
tar -xzf "syft_${SYFT_VERSION}_linux_${ARCH}.tar.gz" syft
sudo install -m 0755 syft /usr/local/bin/syft
rm syft "syft_${SYFT_VERSION}_linux_${ARCH}.tar.gz" "syft_${SYFT_VERSION}_checksums.txt"sha256sum must print syft_1.57.2_linux_amd64.tar.gz: OK (or arm64). If it prints FAILED, delete the download and fetch it again; do not install a file that fails the check.
A binary installed this way gets no updates from apt. To upgrade, run the same commands with a newer SYFT_VERSION from the releases page; install replaces the old file. Anchore also publishes an install script and packages for Homebrew, but the direct download keeps the version you run visible in your notes.
Check it worked
syft version
jq --versionsyft version prints a block that includes Version: 1.57.2. jq --version prints something like jq-1.8.1.
Step 2 · Scan an image from a registry
Point Syft at an image with the registry: prefix. Syft then downloads the image manifest and layers straight from the registry and never asks a local Docker daemon. Multi-architecture images such as Alpine publish one image per platform, so name the platform you ship; otherwise Syft picks the one that matches your machine and two colleagues can get different results.
cd ~/sbom-demo
syft scan registry:alpine:3.24.4 --platform linux/amd64The first run shows a progress display, then a table with the columns NAME, VERSION and TYPE. Every row of an Alpine image has the type apk, Alpine's package format: busybox, musl, apk-tools, ca-certificates-bundle and a dozen or so more.
Alpine layers are a few megabytes, so a scan costs little data. Larger images, such as a full Debian or a Node image, can be hundreds of megabytes per scan; on a metered or prepaid connection, scan once and work from the saved SBOM, as the next steps do. Docker Hub limits how many images an anonymous client may pull per hour, so if a scan fails with toomanyrequests, wait or sign in with docker login (Syft reads the same credentials file).
Check it worked
The table lists busybox and musl with an Alpine version such as 1.37.0-r… for busybox. If you see TYPE values other than apk, check that you typed alpine and not an application image.
Step 3 · Write SPDX and CycloneDX files
The table is for reading. For tools and customers, write a standard format. Two standards dominate:
- SPDX (from the Linux Foundation, also ISO/IEC 5962) grew out of licence compliance. It models packages, files and the relationships between them, and it is the format legal teams and many public-sector buyers ask for.
- CycloneDX (from OWASP) grew out of security tooling. It models components, services and dependencies, and vulnerability scanners and SBOM platforms tend to prefer it.
Both are JSON, both carry purls, and Syft writes either. Pass -o more than once with format=file to get several files from one scan:
cd ~/sbom-demo
syft scan registry:alpine:3.24.4 --platform linux/amd64 \
-o spdx-json=alpine-3.24.4.spdx.json \
-o cyclonedx-json=alpine-3.24.4.cdx.json
ls -l *.jsonNow look at the top of each file:
jq '{spdxVersion, name, packages: (.packages | length), files: (.files // [] | length)}' alpine-3.24.4.spdx.json
jq '{bomFormat, specVersion, components: (.components | length)}' alpine-3.24.4.cdx.json
jq -r '.components | group_by(.type)[] | "\(.[0].type)\t\(length)"' alpine-3.24.4.cdx.jsonThe SPDX file names its version in spdxVersion (such as SPDX-2.3) and keeps packages and files in separate arrays. The CycloneDX file says "bomFormat": "CycloneDX" and puts everything in one components array, told apart by type: library for each apk package, operating-system for Alpine itself, and file for the files those packages own. That is why the raw counts differ between the two formats even though they describe the same image. When you count packages, count library components in CycloneDX and packages minus the image's own entry in SPDX.
If a customer names a format, give them that one. If nobody does, keep both: Syft makes them from the same scan for free.
Check it worked
The first command shows an SPDX 2 version and a package count. The second shows CycloneDX, a specVersion such as 1.6, and a component count. The third prints one line each for file, library and operating-system.
Step 4 · List packages and licences with jq
An SBOM is only useful if you can ask it questions. The CycloneDX file is the easier one to query. List every package with its version and purl:
cd ~/sbom-demo
jq -r '.components[] | select(.type == "library") | [.name, .version, .purl] | @tsv' alpine-3.24.4.cdx.jsonEach line ends in a purl such as pkg:apk/alpine/busybox@1.37.0-r…?arch=x86_64&distro=alpine-3.24.4. The purl is what scanners such as Grype match against vulnerability databases, so it matters more than the bare name.
CycloneDX stores a licence in one of three shapes: an SPDX licence id (MIT), a free-text name when the licence is not on the SPDX list, or an expression that combines several (MIT AND BSD-2-Clause). This query reads whichever is present and counts how often each licence appears:
jq -r '.components[] | select(.type == "library") | .licenses[]? | .license.id // .license.name // .expression' alpine-3.24.4.cdx.json \
| sort | uniq -c | sort -rnThen find the packages under a given licence family, here anything GPL, which is the question a legal review usually starts with:
jq -r '.components[] | select(.type == "library")
| select(any(.licenses[]?; (.license.id // .license.name // .expression) | test("GPL")))
| "\(.name) \(.version)"' alpine-3.24.4.cdx.jsonThe same facts are in the SPDX file under licenseDeclared. Syft fills licenseConcluded with NOASSERTION, because concluding a licence is a human judgement, not something a scanner can make:
jq -r '.packages[] | "\(.name)\t\(.licenseDeclared)"' alpine-3.24.4.spdx.json | head -n 10Check it worked
The licence count shows a handful of entries, with GPL-2.0-only and MIT near the top for Alpine. The GPL query lists busybox among others. In the SPDX output, the image's own entry shows NOASSERTION, and the apk packages show the licence each one declares.
Step 5 · Make an SBOM for a source folder
Syft also reads a project folder. It looks for the files that declare dependencies, such as requirements.txt, package-lock.json, go.mod or Cargo.lock, and records what they pin. That gives you an SBOM before any image exists, for example on every pull request. Make a small Python project:
mkdir -p ~/sbom-demo/app && cd ~/sbom-demo/app
cat > requirements.txt <<'REQ'
httpx==0.28.1
click==8.2.1
REQ
cat > main.py <<'PY'
import click
import httpx
@click.command()
@click.argument("url")
def main(url):
print(httpx.get(url).status_code)
if __name__ == "__main__":
main()
PYA folder has no name or version of its own, so give it one. Those values end up in the SBOM's metadata and tell a reader which release it describes:
cd ~/sbom-demo
syft scan dir:app --source-name sbom-demo-app --source-version 1.0.0 \
-o cyclonedx-json=app-1.0.0.cdx.json
jq -r '.metadata.component | "\(.name) \(.version)"' app-1.0.0.cdx.json
jq -r '.components[] | select(.type == "library") | "\(.name) \(.version) \(.purl)"' app-1.0.0.cdx.jsonA folder scan sees only what the files declare. Here that is the two direct dependencies; httpx itself pulls in httpcore, anyio, certifi and others, which are missing because requirements.txt does not list them. Pin the full tree (with pip-compile, uv lock or pip freeze) and the SBOM lists it too. That gap is also why an image scan and a source scan of the same app give different results: the image contains what was really installed, transitive packages included.
Check it worked
The metadata line prints sbom-demo-app 1.0.0. The component list shows httpx 0.28.1 pkg:pypi/httpx@0.28.1 and click 8.2.1 pkg:pypi/click@8.2.1.
Step 6 · Diff the SBOMs of two image versions
When a base image moves from one release to the next, you want to know what changed underneath you before you ship it. Make an SBOM for the older Alpine 3.23.8 as well, and reduce both to sorted name version lists:
cd ~/sbom-demo
syft scan registry:alpine:3.23.8 --platform linux/amd64 -o cyclonedx-json=alpine-3.23.8.cdx.json
for v in 3.23.8 3.24.4; do
jq -r '.components[] | select(.type == "library") | "\(.name) \(.version)"' "alpine-$v.cdx.json" \
| LC_ALL=C sort -u > "alpine-$v.pkgs.txt"
donejoin lines up the two lists by package name. -a 1 -a 2 keeps packages that exist on only one side, and -e - fills the empty side with a dash. The awk filter drops packages whose version did not change:
cd ~/sbom-demo
LC_ALL=C join -a 1 -a 2 -e - -o 0,1.2,2.2 alpine-3.23.8.pkgs.txt alpine-3.24.4.pkgs.txt \
| awk '$2 != $3 { print $1 ": " $2 " -> " $3 }'Each line reads package: old -> new. A - on the left means the package is new in 3.24.4; a - on the right means it was removed. This short list is what belongs in a pull request description when you bump a base image, and it is far easier to review than the full SBOMs.
Always diff SBOMs made with the same Syft version and options. A newer Syft can find packages an older one missed, and that shows up in the diff as a change to the image when it is only a change to the scanner.
Check it worked
The output has at least a few lines, for example musl, busybox or apk-tools with a new version on the right. If it prints nothing, check that both .pkgs.txt files are non-empty with wc -l alpine-*.pkgs.txt.
Step 7 · Store SBOMs as build artefacts
A tag such as alpine:3.24.4 can be pushed again and point at different content. The digest cannot: it is a hash of the image manifest. File each SBOM under the digest it describes, so nobody has to guess which build a file belongs to. Syft's own JSON format records that digest, so write it alongside the others and read source.metadata.manifestDigest:
cd ~/sbom-demo
syft scan registry:alpine:3.24.4 --platform linux/amd64 \
-o syft-json=alpine-3.24.4.syft.json \
-o spdx-json=alpine-3.24.4.spdx.json \
-o cyclonedx-json=alpine-3.24.4.cdx.json
DIGEST="$(jq -r '.source.metadata.manifestDigest' alpine-3.24.4.syft.json)"
echo "$DIGEST"
mkdir -p "sboms/alpine/${DIGEST#sha256:}"
cp alpine-3.24.4.spdx.json alpine-3.24.4.cdx.json "sboms/alpine/${DIGEST#sha256:}/"
gzip -9 sboms/alpine/*/*.json
find sboms -type fecho prints sha256: followed by 64 hex characters: the digest of the linux/amd64 image, not of the multi-platform index. Scan each platform you ship and file each one under its own digest. SBOM JSON compresses well, so gzip keeps a long archive small.
In CI, make the SBOM in the same job that builds and pushes the image, and keep it with the build. In GitHub Actions (see /tutorials/github-actions-first-workflow) that is an upload step after the scan. Replace ghcr.io/your-org/your-app with your image, and install Syft earlier in the job with the same download and checksum commands as the first step:
- name: Write SBOMs
run: |
syft scan "registry:ghcr.io/your-org/your-app@${IMAGE_DIGEST}" \
-o spdx-json=sbom.spdx.json -o cyclonedx-json=sbom.cdx.json
- name: Keep SBOMs with the build
uses: actions/upload-artifact@v7
with:
name: sbom-${{ github.sha }}
path: sbom.*.jsonHere IMAGE_DIGEST is the digest your build step reports. Workflow artefacts expire after the repository's retention period, so copy SBOMs for releases you ship to long-term storage as well, or attach them to the image itself. Attaching works by signing the SBOM as an attestation that travels with the image in the registry, so anyone who pulls it can fetch and verify the SBOM; /tutorials/sign-and-verify-container-images-with-cosign shows how.
Check it worked
find sboms -type f prints two paths of the form sboms/alpine/<64 hex characters>/alpine-3.24.4.spdx.json.gz and .cdx.json.gz. zcat on either file prints the JSON again.
Step 8 · Clean up
Remove the demo folder. Keep Syft if you will use it again; otherwise remove the binary too:
cd ~
rm -rf ~/sbom-demo
sudo rm /usr/local/bin/syftCheck it worked
ls ~/sbom-demo reports No such file or directory, and command -v syft prints nothing. If it still prints /usr/local/bin/syft, your shell has remembered the old path: run hash -r and try again.
Next steps
- Run these commands on every build:
/tutorials/github-actions-first-workflow.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials