Capture ouput of docker build into a log file?

I’d like to be able to capture the output of a docker build task into a log file.

I assumed that docker build <arguments> --progress=plain >> docker-build.log would suffice however the resulting file is empty.

I’ve tried to see if docker keeps a log file anywhere of the output from builds however I’ve not been able to find any reference to this.

That’s because the output is not on the standard output but the standard error stream. So you can try this to redirect everything into the file:

docker build --no-cache --progress=plain  . &> build.log

or just redirect standard error if you think there should be some other output to show in the terminal

docker build --no-cache --progress=plain  . 2> build.log

Or you can use tee to show the logs and also save it to a file

docker build --no-cache --progress=plain . 2>&1 | tee build.log

If you want to append new logs and not to overwrite on every build, use >> for the redirection as you did originally. If you choose the version with tee, you can use tee -a to append the new logs

3 Likes

That worked perfectly.

Thank you!

I am glad it helped.

When I came back to see your response I noticed I left the --no-cache option in all of my commands. That option is not required of course. You can remove it.