Snippet from my Dockerfile
:
FROM node:12.18.0
RUN echo "hello world"
RUN psql --version
When I run docker build .
I don’t see any output from these two commands even if they are not cached. The documentation says that docker build
is verbose by default. Why am I not seeing the output from commands? I used to see them before.
The output while building:
=> [7/18] RUN echo "hello world" 0.9s
The output I am seeing after building finishes:
=> CACHED [6/18] RUN apt-get install postgresql -y 0.0s
=> [7/18] RUN echo "hello world" 6.4s
=> [8/18] RUN psql --version 17.1s
The Dockerfile
is created from node:12.18.0 which is based on Debian 9.
Docker version 19.03.13, build 4484c46d9d.
6
Answers
The output you are showing is from buildkit, which is a replacement for the classic build engine that docker ships with. You can adjust output from this with the
--progress
option:Adding
--progress=plain
will show the output of the run commands that were not loaded from the cache. This can also be done by setting theBUILDKIT_PROGRESS
variable:If you are debugging a build, and the steps have already been cached, add
--no-cache
to your build to rerun the steps and redisplay the output:If you don’t want to use buildkit, you can revert to the older build engine by exporting
DOCKER_BUILDKIT=0
in your shell, e.g.:or
Just use this flag
--progress=plain
afterbuild
.For example:
OR
If you don’t want to use this flag every time, then permanently tell docker to use this flag by doing:
Here is the official documentation when you type
docker build --help
.As an alternative to specifying the
--progress=plain
option, you can also permanently disable the "pretty" output by setting this env variable in your shell config:In Docker 20.10 i had to use the –no-cache flag, too. Otherwise cached output is not shown.
Do 2 things
docker build .
use thisRUN
command every build (this tricks docker into thinking it hasn’t seen the command before, so it doesn’t use the cached version)Example. If your command is
RUN ls
use this insteadRUN ls && echo sdfjskdflsjdf
(change thesdfjskdflsjdf
to something else each time you build).Why this works
I tried other answers and they all presented problems and imperfections. It’s highly frustrating that Docker doesn’t have some simple functionality like
--verbose=true
.Here’s what I ended up using (it’s ludicrous but it works).
Suppose you want to see the output of
ls
command, this won’t workdocker build .
but this will print the output
docker build --progress=plain
:now try again, it won’t print! – that’s because docker caches the unchanged layer, so the trick is to alter the command each time by adding some nonsense to it
&& echo sdfljsdfljksdfljk
, and changing the nonsense each timedocker build --progress=plain
:So each and every time, I mash the keyboard and come up with a new token. Stupifying. (note that I tried something like
&& openssl rand -base64 12
to generate a random string, but docker realises the code hasn’t changed that doesn’t work).This solution is highly inferior to genuine docker support for printing output to console.
If your error looks something like this:
#7 0.584 /bin/sh: 1: /install.sh: not found
it’s telling you the error is in line number 1. you are running into windows line endings
I was using VS code and I solved it pretty easily by converting the file from CRLF to LF using VS code.
just click on the CRLF button in the bottom right corner of the editor and save the file.
everything should work fine when you build the image now.