scipsycho
scipsycho

Reputation: 587

displaying help messages while docker build

I am building a Dockerfile and I would like to display some help messages while building it.

I also tried RUN echo "installing this" but as expected, it doesn't work.

So, How do I display help messages and if possible while running the docker build command in quiet mode.

Upvotes: 24

Views: 24636

Answers (2)

Dmitriy
Dmitriy

Reputation: 593

I had a similar problem with docker build where RUN echo commands were not showing . I was able to fix it by modifying the build command to

docker build -t hello-world ./ --progress=plain --no-cache

The important thing here is the --progress=plain option as docker defaults to auto and hides too much output. The --no-cache option is necessary to rebuild the container to show all of the output.

Upvotes: 41

ErikMD
ErikMD

Reputation: 14743

A priori RUN echo "installing this" should work and display something. However it would be somewhat bad practice to have a RUN layer with only a single echo command.

Indeed as mentioned in the page dev-best-practices:

If you need to use a version of Docker that does not include multistage builds, try to reduce the number of layers in your image by minimizing the number of separate RUN commands in your Dockerfile. You can do this by consolidating multiple commands into a single RUN line and using your shell’s mechanisms to combine them together.

For additional, related recommendations, there is also a page dockerfile_best-practices.

For the use case you mention in your question, you could either write

RUN echo "install this" && command that install this...

or maybe just

RUN set -x && command that install this...

to automatically display the command that is run during the docker build.

But if you use the docker build --quiet option, I am unsure it is possible to achieve what you want.

So if you really want to have some concise/quiet build log while displaying specific info messages, you could try removing docker build's --quiet option but combine set -x with redirections such as command that install this >/dev/null.

Upvotes: 4

Related Questions