dive icon indicating copy to clipboard operation
dive copied to clipboard

Add option to wrap long commands - Layer Details

Open NJAldwin opened this issue 4 years ago • 7 comments
trafficstars

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?

NJAldwin avatar May 24 '21 15:05 NJAldwin

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.

auktis avatar Oct 20 '21 12:10 auktis

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

docker history <IMAGE> --format "{{.CreatedBy}}" --no-trunc

emazzotta avatar Jan 06 '22 23:01 emazzotta

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.

ZelphirKaltstahl avatar Feb 04 '22 10:02 ZelphirKaltstahl

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)

lutzky avatar Apr 14 '23 12:04 lutzky

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 avatar May 01 '23 22:05 yurenchen000

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

yurenchen000 avatar May 02 '23 07:05 yurenchen000

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

wagoodman avatar Jul 06 '23 15:07 wagoodman