wagoodman / dive

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

Add option to wrap long commands - Layer Details #356

Open NJAldwin opened 3 years ago

NJAldwin commented 3 years ago

With modern Dockerfiles that follow the best practices guides, a lot of images have few layers with very long commands. It's difficult to browse these in dive, as the command gets cut off.

For example, looking at a recent python image:

dive python:3.8-slim-buster
Screenshot_5_24_21__11_47_AM

The highlighted line corresponds to this command in the Dockerfile: https://github.com/docker-library/python/blob/e0e01b8482ea14352c710134329cdd93ece88317/3.8/buster/slim/Dockerfile#L28-L102

Is there any possibility of adding a Wrap toggle for the Layer Details pane, so that the user could expand and view the whole layer command if they desire?

auktis commented 2 years ago

It’s not difficult, it’s impossible to use, because you just can’t see all the line. This is a major regression introduced in version v0.10.0. In version v0.9.2, the command line was correctly wrapped, though it still didn’t work well, because you can’t scroll the "Layer Details" view if it goes beyond the terminal window.

emazzotta commented 2 years ago

Until this is fixed, the commands can be looked up like this:

docker history <IMAGE> --format "{{.CreatedBy}}" --no-trunc
ZelphirKaltstahl commented 2 years ago

The highlighted line corresponds to this command in the Dockerfile: https://github.com/docker-library/python/blob/e0e01b8482ea14352c710134329cdd93ece88317/3.8/buster/slim/Dockerfile#L28-L102

I wouldn't necessarily call that a "best practice". At least not in many contexts for all kinds of images. It completely discards all use of docker build cache for example. It depends heavily on how often you have to change things in the Image. However, this is indeed common with docker images, which are offered as popular base images, not being changed much or generally used as base image and thus not being able to afford many layers (silly layer limitation of docker or aufs).

Many layers are usually created on top of common base images, for the specific use cases of the user. For example I might need a base Debian Python image. Then I install tools and a web service on that image. I would be foolish to put everything into 1 huge command, as I would have no cache at all during development and waste lots of time and computing resources.

However, one might still have very long commands, even when not putting everything into one command. That is simply due to environment variables and flags of commands. Thus a way is needed to view the complete commands somehow. Of course this can de done outside of dive, as mentioned in a previous comment, but it would be nice to have a good way inside the tool.

lutzky commented 1 year ago

Somewhat related: Instead of long one-line commands, heredoc syntax can be used for multi-line commands. Showing this in dive is currently broken, I've sent a fix in https://github.com/wagoodman/dive/pull/443. This is a cleaner way to unify some long commands, and after my fix is quite usable in many cases. (It's a much simpler fix than reasonably wrapping the long commands, I think, so perhaps a useful workaround for now)

yurenchen000 commented 1 year ago

see docker layer history via cli

use dive cli

$ dive IMAGE:TAG -j dive.out
$ cat dive.out | jq '.layer'

use docker cli

$ docker save -o save.tar IMAGE:TAG
$ tar --wildcards -Oxf save.tar *.json | jq '.history?[] | select(.empty_layer!=true)'

// this will filter-out empty layer, like dive does

// seems docker history can't

$ docker history IMAGE:TAG --format '{{.CreatedBy}}' --no-trunc | tac
yurenchen000 commented 1 year ago

Cursor behavior in gocui v1.x seems changed https://github.com/awesome-gocui/gocui/blob/v1.1.0/migrate-to-v1.md#changes-made-to-the-cursor

wagoodman commented 1 year ago

Note: this is partially addressed in https://github.com/wagoodman/dive/pull/399