Skip to main content

Create SBOM: Docker execution guide and CI/CD automation

This page contains the actual Docker commands for syft and cdxgen, the GitHub Actions automation setup, the sample project walkthrough, and troubleshooting.


Running syft with Docker — commands per language/package manager

LanguagePackage managerCommand
JavaMaven/Gradledocker run --rm -v $(pwd):/project anchore/syft:latest /project --output cyclonedx-json > output/sbom/sbom.cdx.json
Pythonpipdocker run --rm -v $(pwd):/project anchore/syft:latest /project --output cyclonedx-json > output/sbom/sbom.cdx.json
Node.jsnpmdocker run --rm -v $(pwd):/project anchore/syft:latest /project --output cyclonedx-json > output/sbom/sbom.cdx.json
Gogo moddocker run --rm -v $(pwd):/project anchore/syft:latest /project --output cyclonedx-json > output/sbom/sbom.cdx.json

Full command (identical for every language; only the directory changes):

Bash
# Create the output/sbom folder
mkdir -p output/sbom

# Generate the SBOM with syft
docker run --rm \
-v $(pwd):/project \
anchore/syft:latest \
/project \
--output cyclonedx-json \
> output/sbom/sbom.cdx.json

Running cdxgen with Docker (when more precise analysis is needed)

Bash
docker run --rm \
-v $(pwd):/app \
-w /app \
ghcr.io/cyclonedx/cdxgen:latest \
-r /app \
-o /app/output/sbom/sbom-cdxgen.cdx.json

Recommended for Java Maven projects. Its dependency resolution is more precise than syft's, and it collects transitive dependencies more completely.


GitHub Actions automation

Integrating SBOM generation into your CI/CD pipeline gives you an up-to-date SBOM automatically for every release.

YAML
# .github/workflows/sbom.yml
name: Generate SBOM

on:
push:
branches: [main]
release:
types: [published]

jobs:
sbom:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Generate SBOM with syft
run: |
docker run --rm \
-v ${{ github.workspace }}:/project \
anchore/syft:latest \
/project --output cyclonedx-json \
> sbom.cdx.json
- name: Upload SBOM as artifact
uses: actions/upload-artifact@v7
with:
name: sbom
path: sbom.cdx.json

Practicing with the samples/ projects

Three sample projects are provided for practice:

  • samples/java-vulnerable/: includes log4j-core 2.14.1 → expect CVE-2021-44228 to be detected
  • samples/python-mixed-license/: mixed GPL use → expect a license conflict to be detected
  • samples/nodejs-unlicensed/: local package with no declared license → expect an unidentified license (NOASSERTION) to be detected
Bash
# Practice with the java-vulnerable sample
docker run --rm \
-v $(pwd)/samples/java-vulnerable:/project \
anchore/syft:latest \
/project --output cyclonedx-json \
> output/sbom/java-vulnerable.cdx.json

Troubleshooting

SymptomCauseSolution
SBOM is empty (components: [])No lock fileCheck for package-lock.json, requirements.txt, pom.xml, etc.
SBOM is empty but there is no errorDocker file-sharing restriction — the mount resolves to an empty directory (colima, etc.)Check that the working directory is included in Docker Desktop > Settings > Resources > File Sharing (or your colima mount settings)
Docker volume mount errorPath problemSwitch to an absolute path: -v /full/path:/project
Permission deniedPermission problemUse sudo or add yourself to the Docker group
Image pull takes a long timeNetworkNormal on the first run; the cache is used afterwards