55

How do we see full commands in the third column (CREATED BY) in the output of docker history command?

$ docker history docker.company.net/docker-base-images/image:1.0

IMAGE               CREATED             CREATED BY                                      SIZE
c0bddf343fc6        7 days ago          /bin/sh -c #(nop)  LABEL com.company.build.r…   0B                  
<missing>           7 days ago          /bin/sh -c #(nop)  ARG commit                   0B                  
<missing>           7 days ago          /bin/sh -c #(nop)  ARG date                     0B                  
<missing>           7 days ago          /bin/sh -c #(nop)  ARG repo                     0B                  
<missing>           7 days ago          /bin/sh -c #(nop)  ARG org                      0B                  
<missing>           7 days ago          /bin/sh -c #(nop)  ARG version                  0B                  
<missing>           7 days ago          /bin/sh -c #(nop)  USER [company]               0B                  
<missing>           7 days ago          /bin/sh -c apk --no-cache add openjdk8-jre-b…   72.2MB              
<missing>           7 days ago          /bin/sh -c #(nop)  USER [root]                  0B                  
<missing>           7 days ago          /bin/sh -c #(nop)  USER [company:company]       0B                  
<missing>           7 days ago          |5 commit=d64d27b07439e6cfff7422acafe440a946…   3.92MB              
<missing>           7 days ago          /bin/sh -c #(nop)  LABEL com.company.build.r…   0B                  
<missing>           7 days ago          |5 commit=d64d27b07439e6cfff7422acafe440a946…   4.85kB              
<missing>           7 days ago          /bin/sh -c #(nop)  ARG commit                   0B                  
<missing>           7 days ago          /bin/sh -c #(nop)  ARG date                     0B                  
<missing>           7 days ago          /bin/sh -c #(nop)  ARG repo                     0B                  
<missing>           7 days ago          /bin/sh -c #(nop)  ARG org                      0B                  
<missing>           7 days ago          /bin/sh -c #(nop)  ARG version                  0B                  
<missing>           5 weeks ago         /bin/sh -c #(nop)  CMD ["/bin/sh"]              0B                  
<missing>           5 weeks ago         /bin/sh -c #(nop) ADD file:88875982b0512a9d0…   5.53MB              

The third column (CREATED BY) is abbreviating the commands which makes it hard to reconstruct the original Dockerfile. Is it possible to get the full commands in the third column?

Thanks for reading.

user674669
  • 10,681
  • 15
  • 72
  • 105

2 Answers2

67

You can add the flag --no-trunc to see the full command.

Alassane Ndiaye
  • 4,427
  • 1
  • 10
  • 19
18

I needed to see the full build history without truncated build steps in a tabular format for debugging purposes. The Docker Docs examples are often incomplete (or non-existent). The accepted answer by @Alassane_Hdiaye can work, but throws an error if used in the wrong place. After a couple tries, I got the GoLang template table formatter to produce the result I needed.

The Docker GoLang template --format option works with docker history, but must be entered AFTER --format, because it modifies --format, NOT docker history. The docker history command takes only 1 argument. The --format option changes the output of docker history, and --no-trunc modifies the --format option.

The command sequence must be

docker history <image-id> --format <GoLang template spec> --no-trunc

The --no-trunc option follows --format on the command line, because it modifies the --format option.


So for the fully history in a tabular format:

docker history <image-id> --format "table{{.ID}}, {{.CreatedBy}}" --no-trunc

The output is messy, because Dockerfile RUN commands can wrap many lines.

So pipe the result to a CSV file and open it in Excel (for lack of a better table viewer).

docker history <image-id> --format "table{{.ID}}, {{.CreatedBy}}" --no-trunc > image-id-history.csv

So now I can see complete build instructions in Excel without truncation.


As a side note, Docker history does not output RUN and other dockerfile build keywords, but these can be inferred. But at least full commands from the complete history are available.

Rich Lysakowski PhD
  • 2,702
  • 31
  • 44
  • 2
    This is simply not true. I just ran the command `docker history --no-trunc --format "{{.ID}}: {{.CreatedBy}}" ` and got the desired output, without any problem. The `--no-trunc` option could be placed *before* the `--format` as well – Bak Itzik Mar 31 '22 at 20:46
  • 1
    Might've been true with the past versions of docker but now can confirm what @BakItzik said. Though valuable answer nonetheless since bare `--no-trunc` is unreadable due to the whitespace overflow. – bravmi Aug 10 '22 at 08:28