A Docker container scanner that automatically generates Software Bill of Materials (SBOMs) for running containers and uploads them to OWASP Dependency-Track for vulnerability analysis.
- Scans all running Docker containers on startup
- Watches Docker events for new containers and scans them automatically
- Generates CycloneDX SBOMs using Trivy
- Uploads SBOMs to Dependency-Track with proper tagging
- Groups projects under a parent project by hostname
- Clones vulnerability analysis decisions when container versions change
- Automatically cleans up stale projects when containers are removed
- Marks projects as inactive when containers are stopped for extended periods
- Caches recently scanned image list to avoid redundant scans
- Configurable scan schedule via cron expression
-
Copy the example environment file:
cp .env.example .env
-
Edit
.envwith your Dependency-Track credentials:DTRACK_URL=https://dependency-track.example.com DTRACK_API_KEY=your-api-key-here
-
Start the scanner:
docker compose up -d
To use a custom image, set
SCANNER_IMAGE:SCANNER_IMAGE=my-registry/dtrack-docker-scanner:v1.0.0 docker compose up -d
docker run -d \
--name dtrack-docker-scanner \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-e DTRACK_URL=https://dependency-track.example.com \
-e DTRACK_API_KEY=your-api-key \
ghcr.io/janhouse/dtrack-docker-scanner:latestAll configuration is done via environment variables:
| Variable | Description |
|---|---|
DTRACK_URL |
Dependency-Track API URL (e.g., https://dtrack.example.com) |
DTRACK_API_KEY |
API key with permissions to create/update projects and upload BOMs |
| Variable | Default | Description |
|---|---|---|
SCAN_INTERVAL |
0 */6 * * * |
Cron expression for scheduled scans |
SCAN_ON_START |
true |
Run a full scan when the container starts |
EXCLUDE_IMAGES |
`` | Comma-separated list of image name patterns to skip |
DTRACK_PARENT_PROJECT |
`` | Parent project name to group all scanned containers under |
SCANNER_HOSTNAME |
<container hostname> |
Hostname used for tagging projects |
CLEANUP_STALE |
true |
Remove projects for containers no longer running |
SCAN_CONCURRENCY |
2 |
Number of concurrent SBOM uploads |
WATCH_DOCKER |
true |
Watch Docker events for new containers |
CACHE_TTL_MINUTES |
60 |
How long to cache scanned image hashes |
INACTIVE_AFTER_MINUTES |
60 |
Mark project inactive after container stopped this long |
INITIAL_CLEANUP_DELAY_MINUTES |
3 |
Delay cleanup after initial scan to allow other containers to start |
TZ |
UTC |
Timezone for cron schedule |
- On startup, the scanner lists all running Docker containers
- For each container, it generates a CycloneDX SBOM using Trivy
- The SBOM is uploaded to Dependency-Track with tags:
- Image base name
host:<hostname>- identifies which host the container runs ondocker-scanner- marks it as scanner-managedcompose:<project>- compose project name (if applicable)imageid:<hash>- Docker image hash for deduplication
When WATCH_DOCKER=true, the scanner listens for Docker events:
- Container start: Scans new containers immediately (if not recently scanned)
- Container stop/die: Tracks stopped containers and marks them inactive after the configured timeout
- New containers create new projects in Dependency-Track
- When a container image is updated, analysis decisions are cloned from the old version
- Old versions are deleted after successful clone
- Stopped containers are marked inactive (not deleted) after the configured timeout
- Containers that restart are automatically reactivated
The scanner avoids redundant scans by:
- Checking a local cache of recently scanned image hashes
- Querying Dependency-Track for existing projects with matching
imageid:tags - Only scanning images that don't exist in either cache
- Bun
- Docker
# Install dependencies
bun install
# Run in development mode
bun run dev
# Type checking
bun run typecheck
# Linting
bun run lint
bun run lint:fix# Build Docker image
docker build -t dtrack-docker-scanner .
# Or using compose
docker compose buildThis project includes Gitea Actions workflows for automated building and SBOM generation.
Builds and pushes the Docker image to container registries.
Inputs:
custom_tags- Comma-separated version tags (e.g.,v1.0.0,v1.0)push_to_github- Also push to GitHub Container Registry
Required Repository Variables:
REGISTRY_URL- Primary container registry URLREPOSITORY_IMAGE- Full image reference (e.g.,registry.example.com/org/image:latest)GHCR_IMAGE- GitHub Container Registry image (e.g.,ghcr.io/org/image:latest)
Required Secrets:
REGISTRY_USERNAME- Primary registry usernameREGISTRY_ACCESS_TOKEN- Primary registry password/tokenGHCR_USERNAME- GitHub usernameGHCR_TOKEN- GitHub personal access token withwrite:packagesscope
Generates SBOM for the built container and uploads to Dependency-Track. Runs automatically after successful builds.
Inputs:
include_github- Also upload SBOM forgithub-latestversioncustom_tags- Comma-separated version tags to upload SBOMs for
Required Secrets:
ACTIONS_GITEA_TOKEN- Token for downloading artifacts between workflowsDEPENDENCY_TRACK_URL- Dependency-Track API URLDEPENDENCY_TRACK_API_KEY- Dependency-Track API keyDEPENDENCY_TRACK_PROJECT_NAME- Project name in Dependency-Track
Runs linting and type checking on pull requests and pushes.
The API key needs the following permissions:
BOM_UPLOAD- Upload SBOMsPROJECT_CREATION_UPLOAD- Auto-create projectsVIEW_PORTFOLIO- List and search projectsPORTFOLIO_MANAGEMENT- Update project properties, delete projects
AGPL-3.0