dive icon indicating copy to clipboard operation
dive copied to clipboard

view / download files from UI

Open robbuckley opened this issue 5 years ago • 14 comments

It would be really handy to be able to view small text files within the UI. Also to be able to download a selected file (to the local filesystem) would be super convenient

robbuckley avatar Sep 05 '19 09:09 robbuckley

@robbuckley, what do you mean with 'the local filesystem' in the context of running dive in a docker container? I'd like it to be the host where the container is running, and not the container itself. However, dive should not be able to 'explore' the host (that's the main purpose of containers). I can think of three options:

  • Make the content of the image available in a predefined location inside the dive container (or a volume). Expect users to use docker exec and/or docker cp.
  • Bind/mount a path. dive would copy selected files to that path.
  • Bind a port. dive would serve directories/files through HTTP, so any browser could be used to download the content.

Based on the last approach, it is already possible to copy all the content of any image to a dummy container and use a tool such as filebrowser to browse it. For example:

FROM filebrowser/filebrowser
COPY --from=wagoodman/dive / /tmp/dive

eine avatar Nov 05 '19 20:11 eine

@1138-4EB i mean the equivalent of docker cp for a single file. For example, while exploring the container contents, select a file, hit 'save locally'. This would save a copy of the file to cwd on the host's filesystem. Or to make it even slicker, pull up a 'save as' dialog, allowing the user to specify a different path/filename to save as on the host

robbuckley avatar Nov 06 '19 21:11 robbuckley

@robbuckley, the point is that, when dive is started as follows:

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

executing docker cp CONTAINER:SRC_PATH DEST_PATH internally will place files in DEST_PATH inside the container, because docker-cli is being executed in it (even though the docker daemon is on the host). Since there is no shared/mount/bind volume, the container cannot copy files to any location on the host. The best it can do is show a command on screen which you can copy and paste on a different shell running on your host.

That's why I suggested three approaches. Precisely, the third option is an alternative to provide a 'Save as' dialog, which must be handled by the host, not by dive.

eine avatar Nov 06 '19 21:11 eine

Slick, I like the idea. To sum it up generically: you're looking for a way while your're browsing layer contents in the UI to export a single file onto your host to you can inspect the contents.

I'll have to think of the best way to do this. Currently dive throws away the file content, as it can take up a lot of space and currently isn't needed for the UI. Though, there are a number of requested features that would require the image file content to implement, so it sounds like there is some gaining appeal. As for how to get the file to the host, @1138-4EB you bring up some good approaches (the third option is clever, but also possibly non-obvious).

wagoodman avatar Nov 09 '19 16:11 wagoodman

export a single file onto your host to you can inspect the contents

In my case, I don't want to export it in order to inspect it, but to use it. For inspecting the contents, I think that dive's UI is ok. Optionally, common utilities such as less or vim can be used.

Regarding my comment above ("the container cannot copy files to any location on the host"), upon further thinking, it might be possible for dive inside the container to copy content to any location on the hots. In order to do so, dive needs to copy the desired files to a docker volume, and then start a temporal container where both the volume and a path from the host are bind.

eine avatar Nov 10 '19 01:11 eine

Do we have an easy way to select and view specific file's content through dive's UI, at least?

brightzheng100 avatar Aug 30 '21 10:08 brightzheng100

It is a great tool which I use regularly. It would be very useful to be able to view / export individual files from specific layers within the dive GUI. It would also be very useful to compare two files between layers (for example if a config file is overridden from one layer to another). It is easy enough to inspect and extract from my own containers. But when inspecting 3rd party containers I want to know what has been modified in order to evaluate why it has been changed.

fstaats avatar Oct 18 '21 16:10 fstaats

I needed this again, so I wasted a day to discover Google crane, which can do this. It still doesn't work with local images, so I tried to fix that, but failed so far.

abitrolly avatar Jan 28 '22 11:01 abitrolly

Got an usecase for this today :

  • an image does not start and exit with a Exited (139) code...
  • No log from docker (just ""),
  • I can't log in and see what happend (container not starting),
  • I don't have the dockerfile (only the image), so I investigate with Dive, and want to review some conf files inside the image.

Thanx for the tool, it's great for other use cases :-)

Rom1deTroyes avatar Sep 22 '22 07:09 Rom1deTroyes

+1 for this feature, viewing file content from UI would be very nice

pibylick avatar Feb 08 '23 08:02 pibylick

the cli way (to get file from docker image layer): https://github.com/wagoodman/dive/issues/336#issuecomment-1530196172

yurenchen000 avatar May 01 '23 20:05 yurenchen000

A simpler CLI method: https://unix.stackexchange.com/questions/331645/extract-file-from-docker-image

TheRealGramdalf avatar Jan 21 '24 05:01 TheRealGramdalf

I've fixed crane to work with image streams from stdout. See above. Now it is possible to list, view and extract files from a local container image using crane and podman itself.

To view /etc/passwd from an image in local podman registry.

export IMAGE=bb2-make-single
podman image save $IMAGE - | crane export - - | tar -Oxf - etc/passwd

Note the missing front slash etc/passwd. With slash it doesn't work.

abitrolly avatar Apr 19 '24 11:04 abitrolly