Is it possible to configure Docker to output timing for the build of a Dockerfile?
We run a medium sized development team and would like to collect statistics on the average build times for our developers' development containers.
Ideally, it should measure the duration of individual steps.
I had the same issue, there is a command line utility called ts taking care of that issue (part of moreutils):
Time whole build
Time steps of build
Output
You can improve the results by only outputting the "Step ?/? :" lines, like so:
Output
JSON output
You can make this into a script if you wanted to run in a CI/CD pipeline, or add to your developer tools.
Output
Script is available as a gist here:
https://gist.github.com/philpoore/05eca572f3aadf70f529c470ac679147
BuildKit, which was experimental in 18.06 and generally available in 18.09, has this functionality built in. To configure the dockerd daemon with experimental mode, you can setup the daemon.json:
Then you can enable BuildKit from the client side with an environment variable:
There's also an option to disable the tty console output which generates output more suitable for scripting with each section having a start, stop, and duration:
I was wondering that too. The only solution I came up with for individual steps is to put
date +'%F %T'
to the end of each step.Output:
In Bash, you could use
echo $SECONDS
which gives time since the Bash session start; ortime ( ... )
(a subshell), but the Docker build environment runs insh
, notbash
.You could use the tool
time
to measure the build times. E.g.For individual build steps it's getting more difficult. You could add a
RUN date
command after each step, but this would add another layer to the image. So it's getting a bit messy.