Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to wrap long commands - Layer Details #356

Open
NJAldwin opened this issue May 24, 2021 · 7 comments
Open

Add option to wrap long commands - Layer Details #356

NJAldwin opened this issue May 24, 2021 · 7 comments

Comments

@NJAldwin
Copy link

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
Copy link

auktis commented Oct 20, 2021

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
Copy link

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

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

@ZelphirKaltstahl
Copy link

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.

@mark2185 mark2185 mentioned this issue Apr 29, 2022
@lutzky
Copy link
Contributor

lutzky commented Apr 14, 2023

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 #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
Copy link
Contributor

yurenchen000 commented May 1, 2023

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
Copy link
Contributor

yurenchen000 commented May 2, 2023

@wagoodman
Copy link
Owner

Note: this is partially addressed in #399

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants