ChatGPT解决这个技术问题 Extra ChatGPT

Why is docker build not showing any output from commands?

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.

Please post formatted code rather than screenshots. Screenshots break search, copy and paste, and are less accessible.

J
Josh Correia

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.

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 ...

The answer regarding --progress=plain does not appear to work anymore. On OS X for me, it merely spits out the command, hash, and step result (e.g. "CACHED"). Only forcibly disabling buildkit returns any useful output now. Is this a recent change, or different depending on platform?
@Jon if the step is cached, no command is run, so there's no output to show. It's the same with or without buildkit.
use docker build --progress=plain --no-cache ... to disable caching and print all output
I'd like to know who in their right mind at Docker decided to hide the caching hashes by default. "Hey we're going to break every Docker debug tutorial on the planet, lets go for it!". They gave a big ol' middle finger to the dev community IMO.
Unfortunately it doesn't seem to work for me.
A
Ash Singh

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")

You might need to clear your docker build cache to see output instead of the hash from the previous build. A brute force way to do that is docker system prune
Does not work with docker-compose, unknown flag: --progress
It works for me, which version of docker-compose are you on ? docker-compose -v @PeterKionga-Kamau
@AshSingh yes of course. docker-compose -p output-test -f docker-compose.custom.yml --verbose up -d --build --progress=plain
@AshSingh aha! ty ty. very true. This explains some of the issues we've been having with options order too.
v
volkit

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 .

--no-cache doesn't just hide the cached output, it disables Docker's layer caching completely. You certainly don't want to use that all the time.
Yes, one thing has nothing to do with the other. Docker by default caches build steps. When you change a line and build again, every subsequent line will be built again by default, because there's no need to repeat existing steps, they're already cached.
r
ruohola

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

This is gold, thanks. Very useful for devops pipelines!