Search code examples
dockerdocker-build

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.


Solution

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