Home > Software engineering >  Docker build: how to get full RUN command output?
Docker build: how to get full RUN command output?

Time:12-11

Is there a way I can see the full RUN command from a Dockerfile built with docker build? E.g. if my Dockerfile has the statement:

RUN cmake \
 -CMAKE_INSTALL_PREFIX="${cmake_install_prefix}" \
 -CMAKE_TOOLCHAIN_FILE="${cmake_toolchain_file}" \
 ${src_dir}

...is there a way I can see the full command, which might be something like cmake -CMAKE_INSTALL_PREFIX=/path/to/wherever -CMAKE_TOOLCHAIN_FILE=/path/to/toolchain.file /path/to/src as well as the full output of running that command?

I build with docker build kit (which I would prefer to not disable), which, by default, collapses output, and ends up looking something like this:

$ docker build -t tmp:tmp --target my_build_stage
...
 => [my_build_stage 4/5] RUN cmake -CMAKE_INSTAL  2.2s
 => [my_build_stage 5/5] WORKDIR /blah            0.1s
...

(let's say that either my terminal is very narrow, or my command is very long), i.e. both the command and its output are truncated/collapsed.

This article says that docker inspect should be used for this purpose, in my case: docker inspect tmp:tmp, and that my answer would be in the $[0].Config.Cmd section of the output, but that section does not contain the relevant information:

$ docker inspect tmp:tmp
[
    {
        ...
        "Config": {
            ...
            "Cmd": [
                "bash"
            ],
            ...

...nor does any other section of that docker inspect command contain the relevant information (a cmake statement in my example).

This article recommends using the --progress plain option to docker build. That uncollapses the command's output, but it still truncates the command itself, e.g.:

$ docker build --progress plain -t tmp:tmp --target my_build_stage
...
#16 [setup 9/9] RUN cmake   -DCMAKE_INSTALL_PREFIX="/pat...
...

Is there a way I can see the full (untruncated) command executed by Dockerfile RUN statements (along with uncollapsed output of the command)?


UPDATE:

The output of my executing docker history:

$ docker history tmp:tmp
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
e3b74f8c442e        11 seconds ago      RUN |5 arch=x86_64 important_path=/home/i…   399B                buildkit.dockerfile.v0
<missing>           13 seconds ago      RUN |5 arch=x86_64 important_path=/home/i…   17.5kB              buildkit.dockerfile.v0
<missing>           15 seconds ago      RUN |5 arch=x86_64 important_path=/home/i…   0B                  buildkit.dockerfile.v0
<missing>           17 seconds ago      WORKDIR /blah                                0B                  buildkit.dockerfile.v0
<missing>           17 seconds ago      WORKDIR /foo…                                0B                  buildkit.dockerfile.v0
...

CodePudding user response:

For a locally built image, you can:

  1. Use docker history tmp, and identify the layer ID where the command is taking place you are interested is taking place.
  2. Run docker inspect on the layer.

So for example, if you are interested in the cmake command, you could:

# Find the layer id
layer_id=$(docker history myimage | awk "/cmake/ {print $1}")

# Run docker inspect on layer 
docker inspect "$layer_id" --format='{{.ContainerConfig.Cmd}}'

CodePudding user response:

Setting env-var PROGRESS_NO_TRUNC=1 along with --progress plain did the trick.

  • Related