Scanning local docker image for vulnerability using Trivy gives unauthorized

Viewed 1286

I've pulled a docker image from a private repository to local and trying to scan the local image with trivy image command. It is pulling the database but showing Unauthorized error to access the local image

scan error: unable to initialize a scanner: unable to initialize a docker scanner: 3 errors occurred:
        * unable to inspect the image (index.docker.io/library/58625f3e2b28:latest): Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
        * unable to initialize Podman client: no podman socket found: stat podman/podman.sock: no such file or directory
        * GET https://index.docker.io/v2/library/58625f3e2b28/manifests/latest: UNAUTHORIZED: authentication required; [map[Action:pull Class: Name:library/58625f3e2b28 Type:repository]]

Docker deamon is running and the image is also in local. Trivy version: 0.22.0
I'm running Trivy as a docker container and using below command to scan the local image

docker run aquasec/trivy image <<imagename>>
1 Answers

The official documentation states that you have to mount the Docker socket if you wish to scan an image on your host machine.

The command would then look like this:

docker run -v /var/run/docker.sock:/var/run/docker.sock aquasec/trivy image <<imagename>>
Related