DockerSelf-Hosting

Trivy with Docker: Scan Images, Dockerfiles and Your Docker Host for Vulnerabilities and Secrets (Linux, Windows, Mac)

Before you start

  • 22 min read

Boxes marked Run in terminal are what you type; plain text explains why. Check what you need first

What you get in one minute#

Trivy is a free, open-source scanner from Aqua Security: it checks your Docker images, Dockerfiles and project folders (and, on Linux, the host's own packages) for known vulnerabilities, risky settings and leaked secrets, so you find the weak spots before someone else does.

Trivy official logo

Logo: the official Trivy project (github.com/aquasecurity/trivy, file docs/imgs/logo.png at tag v0.76.2)

You run Trivy as a one-shot command whenever you want a check. It reads the images your containers use, compares their packages with a database of known problems (CVEs) and prints a list by severity. Setup takes about 20 minutes and adds no always-on service.

WhatValue (official sources, read December 2026)
Current versionTrivy v0.76.2, released 5 November 2026 (previous: v0.76.1, 21 October 2026)
Image to pinaquasec/trivy:0.76.2 (Docker Hub; amd64, arm64, ppc64le, s390x), digest sha256:8f6bb947dbc528902e11f2f5be52f7b519f6a39d5d148f41166f2040499768fb
Time neededAbout 20 minutes (our estimate, not measured)
DiskThe vulnerability database is about 1.8 GB unpacked (the maintainers' figure); the image is about 60 MB compressed
PortsNone for scans; 4954 only in the optional server mode
LicenceApache-2.0; Aqua sells a separate platform built on Trivy, Trivy itself is free
Official docstrivy.dev/docs/latest

At a glance:

  • What it scans: images, folders, Dockerfiles and (on Linux) the host's OS packages.
  • What it finds: known vulnerabilities, risky Dockerfile settings and secrets such as keys and tokens.
  • How it runs: one command, no service.
  • Limits: Compose files get only secret scanning, and a clean report is not proof of safety.

Which version. We pin 0.76.2 and never use latest for a security tool. The incident section below explains why.

How it fits together#

You start a one-shot Trivy container with Docker Compose; it reads your images, folders and optionally the host, downloads a vulnerability database into a cache folder and writes a report.

Trivy flow: you start a one-shot Trivy container with Docker Compose; it reads your images through the Docker socket or from a registry, your project folders and optionally the host; it downloads the vulnerability database from a registry into a cache folder and writes a report; an optional server mode shares the database

Drawn for this guide from the official docs. The dashed parts are optional.

Four words to know:

  • Target: what you scan, such as an image, a folder or a host.
  • Scanner: what Trivy looks for: vulnerabilities, misconfigurations or secrets.
  • Vulnerability database: the list of known CVEs that Trivy downloads into its cache. It is refreshed every 24 hours.
  • Severity: how findings are ranked: UNKNOWN, LOW, MEDIUM, HIGH or CRITICAL.

Before you start#

SystemWhat to have
LinuxDocker Engine and the Compose plugin
WindowsWindows 10 or later, Docker Desktop with the WSL 2 backend (Linux containers), PowerShell
MacDocker Desktop, Intel or Apple Silicon
Run in terminalbash
docker --version
docker compose version

Checklist:

  • [ ] Both commands print a version
  • [ ] About 3 GB of free disk space (database plus cache)
  • [ ] You know which images and folders you want to scan

Tested by DIY Lab Hub: not yet. Commands come from the official docs, read December 2026. We did not run them.

Tip: Start with one image, not your whole server.

The March 2026 supply-chain incident#

A scanner is code you run next to your Docker socket and files, so you should know what happened to Trivy in March 2026. This is Aqua's own account, from advisory GHSA-69fq-xp46-6x23 (published 21 March 2026, severity critical).

On 19 March 2026 an attacker with stolen credentials published a malicious Trivy v0.69.4: binaries, deb and rpm packages, and container images tagged 0.69.4 and latest. The same day they rewrote 76 of the 77 tags of the GitHub Action aquasecurity/trivy-action and all 7 tags of aquasecurity/setup-trivy, so these ran credential-stealing code before the real scan. On 22 March two more Docker Hub images, aquasec/trivy:0.69.5 and 0.69.6, were pushed. No GitHub releases exist for them.

ComponentBad versionWindow (UTC)
Trivy binaries, packages and images (GHCR, ECR Public, Docker Hub)v0.69.4, and latest while it pointed there19 March, about 18:22 to 21:42
trivy-action and setup-trivy76 of 77 trivy-action tags; all 7 setup-trivy tags19 March about 17:43 to 20 March about 05:40 (trivy-action); about 4 hours (setup-trivy)
Docker Hub images aquasec/trivy0.69.5 and 0.69.622 March about 15:43 to 23 March about 01:40

The stealer read SSH keys, cloud credentials, Docker configs and .env files and sent them out. Aqua says you were not affected with Trivy v0.69.3 or earlier, images referenced by digest, builds from source, the official Homebrew formula, or trivy-action 0.35.0. Aqua removed the bad releases within hours; the Docker Hub tags 0.69.4, 0.69.5 and 0.69.6 now return "not found" (checked 1 December 2026).

If a bad version ran in your environment: treat every secret that pipeline could reach as stolen and rotate it. Look for GitHub repositories whose name starts with tpcp-docs, and check workflow logs from 19 and 20 March.

What we do about it:

  • Pin the exact tag and, ideally, the digest. Never use latest.
  • Verify the image with Cosign, using the command from the official docs:
Run in terminalbash
cosign verify aquasec/trivy:0.76.2 \
  --certificate-identity-regexp 'https://github\.com/aquasecurity/trivy/\.github/workflows/.+' \
  --certificate-oidc-issuer "https://token.actions.githubusercontent.com"
  • Mount the Docker socket only for runs that need it, and keep secrets out of the folders you scan.
  • In GitHub Actions, pin to a full commit SHA (Aqua's advice).

Why 0.76.2. It is a normal release of 5 November 2026. GitHub marks the release files immutable and each has a Sigstore bundle. That protects the GitHub downloads; a Docker Hub tag can still move, so pin the digest and verify with Cosign. The advisory lists only 0.69.4 (and Docker Hub 0.69.5 and 0.69.6) as malicious and names no later version. We did not run Cosign ourselves, and the advisory says nothing specific about 0.76.2, so verify it yourself.

Tip: Pin aquasec/trivy:0.76.2 and move the pin on purpose after reading the release notes. A moving tag is exactly how a bad release reaches you.

Step 1: Create the folders and the Compose file#

Everything lives under ~/docker_volumes/trivy. cache keeps the database, reports your result files, work is the folder you scan (mounted read-only), config holds optional ignore files, backups holds backups.

Trivy is a command-line tool, not a service, so our Compose file defines two one-shot jobs started with docker compose run --rm. restart: unless-stopped has no meaning for them and appears only in the optional server (Step 7). trivy has no Docker socket: it pulls images from registries and scans folders. trivy-local also gets the Docker socket, so it can scan images that exist only on this machine. The socket gives root-level control of Docker (:ro would not limit what the API allows), which is why it lives in its own job.

Linux#

Run in terminalbash
mkdir -p ~/docker_volumes/trivy/{cache,reports,config,work,backups}
cd ~/docker_volumes/trivy
echo "SCAN_DIR=./work" > .env
cat > compose.yaml << 'EOF'
x-trivy: &trivy
  image: aquasec/trivy:0.76.2
  environment:
    TRIVY_CACHE_DIR: /cache
    TRIVY_DISABLE_TELEMETRY: "true"
    TRIVY_SKIP_VERSION_CHECK: "true"
    TRIVY_NO_PROGRESS: "true"
  volumes:
    - ./cache:/cache
    - ./reports:/reports
    - ${SCAN_DIR:-./work}:/work:ro
  working_dir: /work

services:
  trivy:
    <<: *trivy
    profiles: ["scan"]
  trivy-local:
    <<: *trivy
    profiles: ["scan"]
    volumes:
      - ./cache:/cache
      - ./reports:/reports
      - ${SCAN_DIR:-./work}:/work:ro
      - /var/run/docker.sock:/var/run/docker.sock
EOF

The volumes list is repeated in trivy-local because a YAML merge replaces the whole list. To scan another project later, change SCAN_DIR in .env.

Windows (PowerShell)#

Codepowershell
$base = "$HOME\docker_volumes\trivy"
foreach ($d in "cache","reports","config","work","backups") {
  New-Item -ItemType Directory -Force "$base\$d" | Out-Null
}
Set-Location $base
"SCAN_DIR=./work" | Set-Content -Encoding ascii .env
@'
x-trivy: &trivy
  image: aquasec/trivy:0.76.2
  environment:
    TRIVY_CACHE_DIR: /cache
    TRIVY_DISABLE_TELEMETRY: "true"
    TRIVY_SKIP_VERSION_CHECK: "true"
    TRIVY_NO_PROGRESS: "true"
  volumes:
    - ./cache:/cache
    - ./reports:/reports
    - ${SCAN_DIR:-./work}:/work:ro
  working_dir: /work

services:
  trivy:
    <<: *trivy
    profiles: ["scan"]
  trivy-local:
    <<: *trivy
    profiles: ["scan"]
    volumes:
      - ./cache:/cache
      - ./reports:/reports
      - ${SCAN_DIR:-./work}:/work:ro
      - /var/run/docker.sock:/var/run/docker.sock
'@ | Set-Content -Encoding ascii compose.yaml

Mac (Terminal)#

Same commands as Linux.

Check it worked. This command lists the two jobs (we expect it to print trivy and trivy-local):

Run in terminalbash
docker compose --profile scan config --services

Step 2: Check the image and download the database#

Linux#

Run in terminalbash
docker run --rm aquasec/trivy:0.76.2 --version
docker buildx imagetools inspect aquasec/trivy:0.76.2
docker compose run --rm trivy image --download-db-only

The first command should show 0.76.2 in the version line. The second prints a Digest: line; compare it with the digest in our table. The third downloads the vulnerability database into cache (a few minutes, about 1.8 GB unpacked). Optional: run the Cosign command now.

Windows (PowerShell)#

Same commands as Linux.

Mac (Terminal)#

Same commands as Linux.

Check it worked. The version line shows 0.76.2, the digest matches, and cache is no longer empty (ls cache, on Windows Get-ChildItem cache).

Tip: The container runs as root, so on Linux the cache and reports files usually belong to root. If you run Trivy with --user, give it a writable --cache-dir (issue 1772).

Step 3: Your first scan#

We scan an old image on purpose (the official docs use it) so you see findings. This job has no socket; it pulls from Docker Hub.

Linux#

Run in terminalbash
docker compose run --rm trivy image --severity HIGH,CRITICAL python:3.4-alpine
docker compose run --rm trivy image --format json --output /reports/python34.json python:3.4-alpine

Windows (PowerShell)#

Same commands as Linux.

Mac (Terminal)#

Same commands as Linux.

Check it worked. You get a table per target. This is the shape from the official docs (an older Trivy version and image, so your numbers will differ):

Codetext
python:3.4-alpine3.9 (alpine 3.9.2)
===================================
Total: 1 (UNKNOWN: 0, LOW: 0, MEDIUM: 1, HIGH: 0, CRITICAL: 0)

| LIBRARY | VULNERABILITY ID | SEVERITY | INSTALLED VERSION | FIXED VERSION |
| openssl | CVE-2019-1543    | MEDIUM   | 1.1.1a-r1         | 1.1.1b-r1     |

The second command writes reports/python34.json. Read each row as: package, CVE, severity, your version, the fixing version.

Step 4: Scan what you really run#

Linux#

List the images your running containers use and scan each one. -T and < /dev/null matter: without them docker compose run swallows the loop's input and only the first image is scanned. --ignore-unfixed hides findings that have no fix yet. If a container's image was re-tagged or removed, docker ps may show an image ID that Trivy cannot find; scan that one by hand.

Run in terminalbash
docker ps --format '{{.Image}}' | sort -u | while read -r img; do
  echo "== $img"
  docker compose run --rm -T trivy-local image --severity HIGH,CRITICAL --ignore-unfixed "$img" < /dev/null
done

To scan the images of one Compose stack, run docker compose config --images in the stack's folder; it prints one image name per line. For an image that exists only locally and without the socket, save it and scan the file (a known bug can hit this):

Run in terminalbash
docker save myapp:1.0 -o work/myapp.tar
docker compose run --rm trivy image --input /work/myapp.tar

Windows (PowerShell)#

With the WSL 2 backend and Linux containers, /var/run/docker.sock is resolved inside Docker Desktop's Linux VM, so the same Compose file should work.

Run in terminalpowershell
docker ps --format '{{.Image}}' | Sort-Object -Unique | ForEach-Object {
  "== $_"
  docker compose run --rm -T trivy-local image --severity HIGH,CRITICAL --ignore-unfixed $_
}
docker compose config --images
docker save myapp:1.0 -o work\myapp.tar
docker compose run --rm trivy image --input /work/myapp.tar

Mac (Terminal)#

Same commands as Linux. In Docker Desktop, switch on Settings, Advanced, Allow the default Docker socket to be used (it asks for your password); it creates /var/run/docker.sock.

Check it worked. Each image gets its own header and table. We did not run these commands, so we show no real result.

Tip: Do not try to fix everything. Begin with HIGH,CRITICAL and --ignore-unfixed. A finding with no fixed version cannot be fixed by you yet.

Step 5: Scan Dockerfiles and project folders#

Put a Dockerfile or a project into work. Trivy checks Dockerfiles for risky settings and plain-text files for secrets. Compose files get only the secret check: the official support table lists Compose as not supported, and the request for it is still open (issue 8729).

Linux#

Run in terminalbash
printf 'FROM alpine:latest\nRUN echo hello\n' > work/Dockerfile
docker compose run --rm trivy config /work
docker compose run --rm trivy fs --scanners vuln,secret,misconfig /work

Windows (PowerShell)#

Codepowershell
"FROM alpine:latest`nRUN echo hello" | Set-Content -Encoding ascii work\Dockerfile
docker compose run --rm trivy config /work
docker compose run --rm trivy fs --scanners vuln,secret,misconfig /work

Mac (Terminal)#

Same commands as Linux.

Check it worked. From the official docs, a finding for a Dockerfile starting with FROM alpine:latest looks like this (your run will list more, such as a missing USER line, check ID AVD-DS-0002):

File contenttext
MEDIUM: Specify a tag in the 'FROM' statement for image 'alpine'
See https://avd.aquasec.com/misconfig/ds001

You can also look at an image's own settings and the secrets hidden in its environment variables: docker compose run --rm trivy image --image-config-scanners misconfig,secret <image>.

Step 6: Scan the Docker host#

Linux#

This checks the host's operating-system packages. The official docs show trivy rootfs --pkg-types os --scanners vuln / for hosts; scanning a read-only mount of / from the container is our adaptation, and we did not run it. The container can read every file of the host while it runs, including keys, so use it only with the pinned image. With --pkg-types os the docs say Trivy does not walk all files.

Run in terminalbash
docker compose run --rm -v /:/hostfs:ro trivy rootfs --pkg-types os --scanners vuln --severity HIGH,CRITICAL /hostfs

Windows (PowerShell)#

There is no host scan. Trivy's list of supported operating systems contains only Linux distributions, and the Docker engine on Windows runs inside Docker Desktop's VM. Scan your images (Step 4) and keep Docker Desktop updated.

Mac (Terminal)#

Same as Windows: no host scan; scan the images (Step 4) and update Docker Desktop.

Check it worked. You get one table named after the detected operating system. Packages inside your containers are not part of this list; they come from the image scans.

Step 7: Share one database with server mode (optional)#

With several machines, one Trivy server downloads the database once and clients ask it. Misconfiguration and secret scanning still run on the client.

Linux#

Run in terminalbash
mkdir -p ~/docker_volumes/trivy-server/cache
cd ~/docker_volumes/trivy-server
echo "TRIVY_TOKEN=<long-random-token>" > .env
chmod 600 .env
cat > compose.yaml << 'EOF'
services:
  trivy-server:
    image: aquasec/trivy:0.76.2
    container_name: trivy-server
    restart: unless-stopped
    command: ["server", "--listen", "0.0.0.0:4954"]
    environment:
      TRIVY_TOKEN: ${TRIVY_TOKEN}
      TRIVY_CACHE_DIR: /cache
      TRIVY_DISABLE_TELEMETRY: "true"
    volumes:
      - ./cache:/cache
    ports:
      - "127.0.0.1:4954:4954"
EOF
docker compose up -d

The port is published on 127.0.0.1 only, so only this machine (or a reverse proxy on it) can reach the server. A client on the same machine runs trivy image --server http://127.0.0.1:4954 <image>. Other machines should use the HTTPS route below: plain http:// sends the token in clear text. Pass the token in the TRIVY_TOKEN environment variable, not on the command line (the header is Trivy-Token), and write http:// or https://, as the protocol is required. Keep clients on the same Trivy version as the server; this is our caution, we did not find a rule in the docs.

Windows (PowerShell)#

Codepowershell
$dir = "$HOME\docker_volumes\trivy-server"
New-Item -ItemType Directory -Force "$dir\cache" | Out-Null
Set-Location $dir
"TRIVY_TOKEN=<long-random-token>" | Set-Content -Encoding ascii .env
@'
services:
  trivy-server:
    image: aquasec/trivy:0.76.2
    container_name: trivy-server
    restart: unless-stopped
    command: ["server", "--listen", "0.0.0.0:4954"]
    environment:
      TRIVY_TOKEN: ${TRIVY_TOKEN}
      TRIVY_CACHE_DIR: /cache
      TRIVY_DISABLE_TELEMETRY: "true"
    volumes:
      - ./cache:/cache
    ports:
      - "127.0.0.1:4954:4954"
'@ | Set-Content -Encoding ascii compose.yaml
docker compose up -d

Mac (Terminal)#

Same commands as Linux.

Check it worked. docker compose ps shows trivy-server running, and docker logs trivy-server --tail 20 shows it listening on port 4954. The first start downloads the database.

Make sense of the results#

Check the severity of each row in the table, then compare the installed version with the fixed version. That tells you how serious it is and whether an update exists. A full scan can be long, so we use a few triage rules:

  • Start with --severity HIGH,CRITICAL --ignore-unfixed.
  • A finding with no fixed version cannot be fixed by you.
  • The fix is usually a newer image tag or a fresh rebuild.
  • A vulnerability inside a container is not always reachable in your setup.

When you accept a risk, list it in a .trivyignore file (put it in the folder you run Trivy from). This example is from the official docs; exp: makes an entry expire.

Codetext
# Accept the risk
CVE-2018-14618

# Accept the risk until 2023-01-01
CVE-2019-14697 exp:2023-01-01

# Ignore a misconfiguration
AVD-DS-0002

A clean report is not proof of safety. In discussion 11699 (20 November 2026), nginx installed from nginx.org's apk repository, as in the official nginx:*-alpine images, is matched against Alpine's own advisories. Newer nginx.org mainline builds can therefore be reported clean although nginx.org lists them as vulnerable. The maintainers say Trivy cannot tell third-party apk packages apart. They advise checking nginx.org's security advisories page, or building on plain alpine and running apk add nginx.

Automation. --exit-code 1 makes Trivy exit non-zero when it finds something; combine it with --severity CRITICAL. A weekly scan at 03:00 on Sunday that sends a message through our ntfy guide:

File contentbash
0 3 * * 0 cd ~/docker_volumes/trivy && docker compose run --rm -T trivy image --severity CRITICAL --exit-code 1 <image> || curl -d "Trivy found problems" https://ntfy.example.com/trivy

On Windows, put the scan in a script and register it:

Run in terminalpowershell
schtasks /Create /SC WEEKLY /D SUN /ST 03:00 /TN "Trivy weekly" /TR "powershell -File <path-to-script>.ps1"

Stacks from Dockge or Komodo can be scanned the same way, Forgejo and Woodpecker CI can run scans in CI, and Harbor uses Trivy as its built-in scanner.

Put it behind HTTPS with Traefik#

Skip this on your own computer. It only matters for the optional server from Step 7, when other machines reach it over the network. Trivy has no web page; its only protection is the token, so use HTTPS. You need a domain, a DNS record and ports 80 and 443. Both routes drop the host port and use a shared proxy network. Create it once if missing:

Run in terminalbash
docker network create proxy

With Traefik#

On a server that already runs Traefik v3 with the Docker provider, add labels to the server's Compose file and remove its ports: block. Our Traefik guide uses the entrypoint https and the resolver le.

File contentyaml
services:
  trivy-server:
    image: aquasec/trivy:0.76.2
    container_name: trivy-server
    restart: unless-stopped
    command: ["server", "--listen", "0.0.0.0:4954"]
    environment:
      TRIVY_TOKEN: ${TRIVY_TOKEN}
      TRIVY_CACHE_DIR: /cache
    volumes:
      - ./cache:/cache
    networks:
      - proxy
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=proxy"
      - "traefik.http.routers.trivy.rule=Host(`trivy.<your-domain>`)"
      - "traefik.http.routers.trivy.entrypoints=https"
      - "traefik.http.routers.trivy.tls=true"
      - "traefik.http.routers.trivy.tls.certresolver=le"
      - "traefik.http.services.trivy.loadbalancer.server.port=4954"

networks:
  proxy:
    external: true

Run docker compose up -d. Check it worked. curl -I https://trivy.<your-domain>/ returns an HTTP status line over HTTPS. Clients then use --server https://trivy.<your-domain>.

Without Traefik: Caddy#

Choose this if you have no Traefik. Caddy gets and renews its own certificates. Use the server file above without the labels: block, then add Caddy in its own folder:

Run in terminalbash
mkdir -p ~/docker_volumes/caddy/{conf,data,config}
cd ~/docker_volumes/caddy
cat > docker-compose.yml << 'EOF'
services:
  caddy:
    image: caddy:2.11.9
    container_name: caddy
    restart: unless-stopped
    ports:
      - "80:80/tcp"
      - "443:443/tcp"
      - "443:443/udp"
    volumes:
      - ./conf:/etc/caddy:ro
      - ./data:/data
      - ./config:/config
    networks:
      - proxy

networks:
  proxy:
    external: true
EOF

Save conf/Caddyfile for a public domain:

File contenttext
trivy.example.com {
    reverse_proxy trivy-server:4954
}

For a home-only name use Caddy's own local certificate with tls internal inside the block (clients must trust Caddy's root certificate). Run docker compose up -d in each folder. Caddy reaches the server by container name, so write trivy-server:4954, never 127.0.0.1:4954.

Check it worked. curl -I https://trivy.example.com/ shows an HTTP status line over HTTPS.

Tip: A certificate error usually means the Caddyfile name differs from the DNS record, or port 80 or 443 is blocked.

Security and testing#

  • The Docker socket is root. Whoever controls the socket controls Docker. Use trivy-local only when you need local images, and never mount the socket into other jobs.
  • Pin tag and digest. In compose.yaml you can write image: aquasec/trivy:0.76.2@sha256:8f6bb947dbc528902e11f2f5be52f7b519f6a39d5d148f41166f2040499768fb, and verify with Cosign (see the incident section).
  • Keep reports private. Reports can contain matches from the secret scanner.
  • Config files load from the current folder. Trivy reads trivy.yaml, .trivyignore and trivy-secret.yaml from where you run it, so an untrusted checkout can change the result. Pick a trusted file with --config.
  • Telemetry. Trivy sends anonymous usage data and checks check.trivy.dev for updates unless you set --disable-telemetry and --skip-version-check. Our Compose file sets both.

Test it. docker compose run --rm trivy --version prints the pinned version, and the Step 3 scan shows findings.

Common mistakes#

MistakeWhy it happensDo this instead
docker compose run in a loop scans only the first imageIt reads the loop's inputAdd -T and < /dev/null
TOOMANYREQUESTS while downloading the databaseGHCR throttles requests (discussion 8009)Keep a persistent cache folder, add more --db-repository locations such as aquasec/trivy-db on Docker Hub or public.ecr.aws/aquasecurity/trivy-db, or host the database yourself
Cannot connect to the Docker daemon at unix:///var/run/docker.sockThe socket is not mounted, or DOCKER_HOST is wrongUse the trivy-local job or pass --docker-host
mkdir /.cache: permission denied when running with --userThe container cannot write its default cache folder (issue 1772)Set --cache-dir to a writable mounted folder
cache may be in use by another processTwo scans share one cache and hit a BoltDB lockRun them one after the other, or add --cache-backend memory
Crash with SIGBUS when two scans download the database togetherBoth unpack into the same folder (discussion 11723)Run --download-db-only once, then scan with --skip-db-update
archive/tar: invalid tar header on a docker save fileDocker's containerd image store mixes compressed and plain layers (discussion 11749)Extract the tar into a folder and scan it with --input, or use --image-src remote
Expecting docker-compose.yml to be checkedCompose is not supported (issue 8729)Scan the images from docker compose config --images, Dockerfiles with trivy config, and the Compose file only for secrets
Trusting a clean report for nginx.org buildsTrivy matches them against Alpine advisories (discussion 11699)Check nginx.org's security advisories page
no space left on device writing /tmp/fanal-...Big image layers fill /tmpSet TMPDIR, add --parallel 1 or use --skip-dirs
Mounting the Docker socket into every runConvenienceOnly the trivy-local job gets it
AI assistants: --security-checks, --vuln-type, --light, --skip-update, trivy docker-composeOld flags and commands that are not in the v0.76.2 option listUse --scanners, --pkg-types and --skip-db-update; Compose has no Trivy command
AI assistants: docker run aquasec/trivy trivy image ..., --scanners config, tags latest or 0.69.4 to 0.69.6The image's entrypoint is already trivy, the scanner is called misconfig, and those tags are unsafe or unpinnedLeave out the extra trivy, use --scanners misconfig, pin 0.76.2

Tip: Run docker compose run --rm trivy --version after every change of the pin.

Tip: Keep the cache folder between runs, or every scan downloads the database again.

Tip: Read the release notes before you move the pin to a newer tag.

Troubleshooting#

ProblemSolution
Image not foundCheck the image name and the registry part of the name
TimeoutAdd --timeout 15m
Database download failsdocker compose run --rm trivy image --download-db-only
Cache or database looks brokendocker compose run --rm trivy clean --all
Certificate error with a private registryAdd --cacert /path/ca.pem

Error texts, as the official troubleshooting page shows them:

Cannot connect to the Docker daemon#

Codetext
FATAL image scan error: scan error: unable to initialize a scanner: unable to initialize an image scanner: ... docker error: unable to inspect the image (...): Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Trivy found the image nowhere (Docker Engine, containerd, Podman, registry). Check for a typo, a missing registry prefix, an unmounted socket, a wrong DOCKER_HOST or a missing login.

Timeout#

Run in terminaltext
analyze error: timeout: context deadline exceeded

Add --timeout 15m.

No space left on device#

Run in terminaltext
write /tmp/fanal-3323732142: no space left on device

Set TMPDIR to a bigger disk, or use --parallel 1 or --skip-dirs.

Cache lock#

Run in terminaltext
cache may be in use by another process

One scan at a time, or --cache-backend memory.

Denied from GHCR#

Codetext
GET https://ghcr.io/token?scope=repository%3Aaquasecurity%2Ftrivy-db%3Apull&service=ghcr.io: DENIED: denied

A stale registry token. Run docker logout ghcr.io or unset GITHUB_TOKEN.

Database download failed#

Codetext
FATAL failed to download vulnerability DB

Usually a firewall; add mirrors with --db-repository. For x509: certificate signed by unknown authority, pass the registry's CA with --cacert.

Known bugs#

Open in December 2026:

  • docker save tar fails (discussion 11749): extract the tar into a folder (mkdir image-oci; tar -xf image.tar -C image-oci) and scan with --input image-oci, or use --image-src remote. The cause is in a library Trivy uses.
  • Parallel database download crash (discussion 11723): --download-db-only once, then --skip-db-update, or use server mode.
  • nginx.org apk false negative (discussion 11699): see "Make sense of the results".
  • No Compose checks (issue 8729).

For anything new, use GitHub Discussions: Trivy takes bug reports, questions and requests there, and issues opened by non-maintainers are closed straight away.

Updates and backups#

Update. Change the pinned tag in compose.yaml, read the release notes and the security advisories first, then pull and check:

Run in terminalbash
cd ~/docker_volumes/trivy
docker compose --profile scan pull
docker compose run --rm trivy --version

Our Diun guide can tell you when a new tag exists. On Windows, run the same commands in PowerShell from $HOME\docker_volumes\trivy.

Backup. The cache needs no backup, because it downloads again. Back up the Compose file, .env, config and reports.

Linux and Mac#

Run in terminalbash
cd ~/docker_volumes/trivy
tar -czf backups/trivy-$(date +%F).tar.gz compose.yaml .env config reports

Schedule it at 03:00 with crontab -e, and delete old archives now and then (for example find backups -name 'trivy-*.tar.gz' -mtime +30 -delete):

File contentbash
0 3 * * * cd ~/docker_volumes/trivy && tar -czf backups/trivy-$(date +\%F).tar.gz compose.yaml .env config reports

Windows (PowerShell)#

Codepowershell
Set-Location "$HOME\docker_volumes\trivy"
Compress-Archive -Path compose.yaml,.env,config,reports -DestinationPath "backups\trivy-$(Get-Date -Format yyyy-MM-dd).zip"

Run it daily from Task Scheduler (schtasks /Create /SC DAILY /ST 03:00 /TN "Trivy backup" /TR "powershell -File <path-to-script>.ps1").

Restore test#

Run in terminalbash
mkdir /tmp/trivy-restore
tar -xzf ~/docker_volumes/trivy/backups/trivy-<date>.tar.gz -C /tmp/trivy-restore
docker compose -f /tmp/trivy-restore/compose.yaml --profile scan config --services

On Windows use Expand-Archive. The command must list trivy and trivy-local. For volume-level backups see our Docker Volume Backup guide.

Performance and resources#

We did not measure RAM or CPU, and the docs give no minimum. From the official sources:

  • Disk: the unpacked vulnerability database is about 1.8 GB; the image is about 60 MB compressed.
  • Layer cache: results are stored by layer, so repeat scans are faster.
  • Parallel work: --parallel (default 5) sets how many layers run at once; --parallel 1 saves disk. --cache-backend memory allows parallel scans without lock errors but saves no results.
  • Speed: skip big folders with --skip-dirs. Watch a scan with docker stats.

FAQ#

Is Trivy better than Grype or Docker Scout? We did not compare them here. Trivy covers vulnerabilities, misconfigurations and secrets in one tool.

Is it free? Yes, Apache-2.0. Aqua sells a platform built on it.

Does it phone home? It sends anonymous usage data and checks for updates. Our Compose file switches both off with TRIVY_DISABLE_TELEMETRY and TRIVY_SKIP_VERSION_CHECK.

Can it scan a private registry? Yes. See the private registries page for the login options; we do not repeat them here.

How do you say the name? "tri" as in trigger, "vy" as in envy.

Sources#

Checked against the official docs on 2026-12-01.