wagoodman / dive

A tool for exploring each layer in a docker image
MIT License
44.64k stars 1.69k forks source link

Doesn't use socket from current docker context #412

Open bzoks opened 1 year ago

bzoks commented 1 year ago

In Docker Desktop (for Linux), when trying to analyze local image, dive doesn't use current docker context endpoint (socket), but apparently always uses "default" endpoint (/var/run/docker.sock), which means it fails to access images built under Docker Desktop environment. Example: Docker Desktop turned off. Built an image. I'm able to analyze it:

$ dive 627547a71182
Image Source: docker://627547a71182
Fetching image... (this can take a while for large images)
Analyzing image...
Building cache...

When I start Docker Desktop (or switch docker context), this same image is still accessible by dive, even if it is not available for docker (under current context):

$ docker image inspect 627547a71182
[]
Error: No such image: 627547a71182

When listing images from current (Docker Desktop) context, listed-ones are not accessible to dive:

$ docker image ls
REPOSITORY                                                          TAG          IMAGE ID       CREATED         SIZE
something_phpfpm-pa                                                latest       36328f223adc   11 hours ago    114MB

$ dive 36328f223adc
Image Source: docker://36328f223adc
Fetching image... (this can take a while for large images)
Handler not available locally. Trying to pull '36328f223adc'...
Using default tag: latest
Error response from daemon: pull access denied for 36328f223adc, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
cannot fetch image
exit status 1

Output of docker context ls:

$ docker context ls
NAME                TYPE                DESCRIPTION                               DOCKER ENDPOINT                                    KUBERNETES ENDPOINT   ORCHESTRATOR
default             moby                Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                                              swarm
desktop-linux *     moby                                                          unix:///home/bostjan/.docker/desktop/docker.sock                         
ecs-prod            ecs  

(asterix on desktop-linux line shows which context is current, so which will be used for all docker commands).

I tried also running dive using docker run and mounting correct endpoint (so the one from current context), but it still didn't worked...

More info on docker contexts in scope of Docker Desktop: Switch between Docker Desktop and Docker Engine

thediveo commented 1 year ago

bump: please make the Docker REST API endpoint configurable on CLI, so that dive can also be directly used with other engines, such as podman that support the Docker REST API; these tend to run on their own socket API paths in order to allow side-by-side co-existance.

kizdebski commented 1 year ago

Hi.

I have just faced with this problem. Use this environment variable to change default socket. DOCKER_HOST=unix:///home/kamil/.docker/desktop/docker.sock

Of course home catalog may be different :)

tomharrisonjr commented 1 year ago

On macos, if you have Advanced/User settings ("Choose how to configure the installation of Docker's CLI tools"), you'll need to do this to make local builds work:

export DOCKER_HOST=unix:///Users/yourusername/.docker/run/docker.sock