Reputation: 6073
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.
Upvotes: 560
Views: 444344
Reputation: 4847
Just use this flag --progress=plain
after build
.
For example:
docker compose build --progress=plain <container_name>
OR
docker build --progress=plain .
If you don't want to use this flag every time, then permanently tell docker to use this flag by doing:
export BUILDKIT_PROGRESS=plain
Here is the official documentation when you type docker build --help
.
--progress string Set type of progress output (auto, plain, tty). Use plain to show container output (default "auto")
Upvotes: 188
Reputation: 119
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.
Upvotes: 0
Reputation: 52728
docker build .
use thisdocker build . --progress=plain
RUN
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 instead RUN ls && echo sdfjskdflsjdf
(change the sdfjskdflsjdf
to something else each time you build).
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 work docker build .
RUN ls
but this will print the output docker build --progress=plain
:
RUN ls
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 time docker build --progress=plain
:
# This prints
RUN ls && echo sdfljsdfljksdfljk
# Next time you run it use a different token
RUN ls && echo sdlfkjsldfkjlskj
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.
Upvotes: 42
Reputation: 264811
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:
--progress string Set type of progress output (auto, plain, tty). Use plain to show container output
(default "auto")
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 the BUILDKIT_PROGRESS
variable:
export BUILDKIT_PROGRESS=plain
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:
docker build --progress=plain --no-cache ...
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.:
DOCKER_BUILDKIT=0 docker build ...
or
export DOCKER_BUILDKIT=0
docker build ...
Upvotes: 782
Reputation: 1621
In Docker 20.10 i had to use the --no-cache flag, too. Otherwise cached output is not shown.
docker build --progress=plain --no-cache .
Upvotes: 52
Reputation: 24107
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:
export BUILDKIT_PROGRESS=plain
Upvotes: 34