6

In the installation page for Trivy there is no mention of Windows.

I have Docker for Windows installed so the Docker method looks promising but there are a couple of things I'm not sure of:

  1. What should I set the cache directory to?
  2. Will I need to "mount docker.sock"? And if so, will I need to replace the /var/run and $HOME/Library/Caches directories in that command with something more "Windows-ey"?

The aim is to scan an image that I built using Docker for Windows.

Steve Chambers
  • 37,270
  • 24
  • 156
  • 208

7 Answers7

4
  1. Install Docker for Windows
  2. Install Git Bash
  3. Open a Git Bash Shell on Windows
  4. Execute the command: docker pull aquasec/trivy:0.19.2
  5. docker run --rm -v C:\Users\<your foldername>:/root/.cache/ aquasec/trivy:0.19.2 aquasec/trivy:0.19.2 python:3.4-alpine
  6. The scan will start to run. It may take a few minutes to return any response.
Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
DonaldM
  • 64
  • 2
  • the documentaiton mentions about having to mount docker.sock. How does that translate to running trivy in windows? https://aquasecurity.github.io/trivy/v0.22.0/getting-started/installation/ – Stealth Rabbi Jan 28 '22 at 13:43
3

With Docker Deskttop for windows installed you can open a terminal (recomended powershell for the next command).

docker run --rm -v ${PWD}/tmp:/root/.cache/ -v //var/run/docker.sock:/var/run/docker.sock  aquasec/trivy <image>

You can use your actual path with this command. It´s better than use absolute paths. Also, you can mount the docker socket to trivy to scan your downloaded images.

Pabpereza
  • 131
  • 4
2

Basically I don't think this is achievable for this exact scenario. The closest way around is to run trivy in WSL, but that isn't technically running on Windows directly.

https://github.com/aquasecurity/trivy/issues/1103

E_net4
  • 27,810
  • 13
  • 101
  • 139
yut6CUZg
  • 41
  • 3
1
  1. Install Go (https://go.dev/doc/install)
  2. Pull Trivy and go in the pulled directory
git clone --depth 1 --branch v0.32.0 https://github.com/aquasecurity/trivy
cd trivy
  1. Install Trivy

go install .\cmd\trivy

Scapal
  • 31
  • 3
  • No luck with this method: ```no required module provides package .cmdtrivy;``` – kdlannoy Oct 18 '22 at 07:13
  • @kdlannoy if you are running from a bash shell in Windows you'll need to escape the '\', so `go install .\\cmd\\trivy` – prunge Nov 22 '22 at 23:30
0

First, I used the WSL to scan the windows containers. Last, I used the go compiler to build a trivy.exe.

Both of these 2 ways work well.

Edwin An
  • 14
  • 3
0

Able to run the scan by running the below command for manifest scanning:

docker run --rm -v C:/projects/abc:/test aquasec/trivy:latest --exit-code 0 --severity UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL --format template --template "@contrib/html.tpl" -o /test/manifest-scanning-report.html config /test/k8s_dir

This will generate a manifest-scanning-report.html under C:/projects folder.

Kuppusamy
  • 65
  • 1
  • 6
-1

The above answer is bit outdated. Here is the correct one with slight modification.

Open a Git Bash Shell on Windows Execute the commands below:

  1. docker pull aquasec/trivy:latest
  2. docker run --rm -v [YourLocalDir]:/root/.cache/ aquasec/trivy:latest [COMMAND_TO_RUN] [YOUR_IMAGE_NAME]

E.g. If you want to run a scan on a docker image then run below command.

docker run --rm -v ./:/root/.cache/ aquasec/trivy:latest image ubuntu:22.04

You can scan filesystem,kubernetes and other things also by changing the COMMAND_TO_RUN. Reference Doc: https://aquasecurity.github.io/trivy/v0.22.0/getting-started/cli/

Pankaj Devrani
  • 510
  • 1
  • 10
  • 28