wagoodman / dive

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

"Building cache" for minutes with hello-world #167

Open fidian opened 5 years ago

fidian commented 5 years ago

I'm running Docker on my Mac using the following command:

docker run --rm -it \
      -v /usr/local/bin/docker:/bin/docker \
      -v /var/run/docker.sock:/var/run/docker.sock \
      -v  "$(pwd)":"$(pwd)" \
      -w "$(pwd)" \
      -v "$HOME/.dive.yaml":"$HOME/.dive.yaml" \
      wagoodman/dive:latest hello-world

Its output seems stuck when it is analyzing the image.

Fetching image...
Parsing image...
  ├─ [layer:  1] d5b5217f651efe1 : [==============================>] 100 % (1/1)
  ╧
Analyzing image...
Building cache...

I've waited minutes for it to build the cache on this 1.85kB image.

Client: Docker Engine - Community
 Version:           18.09.1
 API version:       1.39
 Go version:        go1.10.6
 Git commit:        4c52b90
 Built:             Wed Jan  9 19:33:12 2019
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.1
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       4c52b90
  Built:            Wed Jan  9 19:41:49 2019
  OS/Arch:          linux/amd64
  Experimental:     true
eine commented 5 years ago

I found a similar behaviour when running the container on Win10 from MINGW64 without -it:

docker run --rm -v //var/run/docker.sock://var/run/docker.sock wagoodman/dive <IMAGE>

wagoodman commented 5 years ago

It seems that the problem is not in building the cache, which is the apparent last step, but actually in starting the UI (gocui/termbox). I haven't pinpointed the root cause yet, however, it appears to be a race condition on the startup of the process that only shows itself when run in a container. With larger images, there is enough time spent fetching, parsing, and analyzing the image (even relatively small images) such that the problem does not present itself.

For instance, as you mentioned, this will not work:

docker run --rm -it \
      -v /var/run/docker.sock:/var/run/docker.sock \
      wagoodman/dive:latest hello-world

However, this will work (shelling into the container and running dive manually):

docker run --rm -it \
      -v /var/run/docker.sock:/var/run/docker.sock \
      wagoodman/dive:latest sh
# /dive hello-world

After a bit of trial and error, it seems that the threshold for this behavior is at ~25ms after the container/processes starts up --so a sleep of 100ms after start up seems to be a good enough workaround for now. I'm not a fan of phantom sleeps making behavior "better", so I won't close this issue yet.

This workaround will make it in the next release.

eine commented 5 years ago

However, this will work (shelling into the container and running dive manually):

docker run --rm -it \
      -v /var/run/docker.sock:/var/run/docker.sock \
      wagoodman/dive:latest sh
# /dive hello-world

Is this feature still available? I just tried:

# winpty docker run --rm -it \
>       -v //var/run/docker.sock://var/run/docker.sock \
>       wagoodman/dive:latest sh
Image Source: docker://sh
Fetching image... (this can take a while for large images)
Handler not available locally. Trying to pull 'sh'...
Using default tag: latest
Error response from daemon: pull access denied for sh, repository does not exist or may require 'docker login': denied: requested acce
ss to the resource is denied
cannot fetch image
Failed to write to log, invalid argument
exit status 1
wagoodman commented 5 years ago

It does as long as I put in the right command (my bad, I missed --entrypoint ''):

$ docker run --rm -it \
>       -v /var/run/docker.sock:/var/run/docker.sock \
>       --entrypoint '' wagoodman/dive:latest sh
# dive hello-world
Image Source: docker://hello-world
Fetching image... (this can take a while for large images)
Analyzing image...
Building cache...
# 
wyckster commented 4 years ago

On Windows, double-quotes are required:

docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock --entrypoint "" wagoodman/dive:latest sh

Otherwise you'll get:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"''\": executable file not found in $PATH": unknown.

eine commented 4 years ago

On Windows, double-quotes are required

Is this with cmd, powershell or WSL? On MSYS2/MINGW, either ' or " work.

This issue seems to be solved for me with the latest wagoodman/dive:latest image. It shows a legit error if -t is not used. It crashes if winpty is not used (#253). But it is not frozen in "Building cache" anymore. @fidian, does the latest image work for you?

@wagoodman, I found an unexpected behaviour: step 'Fetching image...' takes around 18s for a given image (no matter if it is already available locally), and 'Analizing image...' is then printed together with 'Building cache...'. I believe that those 18s correspond to 'Analizing', but the message is being printed after analysis, instead of before. Otherwise, it would mean that dive is downloading the image every time.

jkpubsrc commented 3 years ago

I seem to run into a similar problem: No more output after "Building cache ...", no error message, nothing.

System: Windows 10

Release: Most recent dive for Windows, downloaded today.

In other words: I can't run it at all on Windows here.

eine commented 3 years ago

@jkpubsrc I cannot reproduce. I just tried the latest wagoodman/dive:latest on Windows 10 (from MSYS2) using Docker Desktop 3.5.2 with ther Hyper-V engine. Can you provide more info about your setup and the command you are trying to execute?