Docker Community Forums

Share and learn in the Docker community.

The best Dockerfile RUN format

We all know there is a bit of strategy when creating Dockerfiles to reduce size & increase efficiency. One (basic) practice I have come to terms with is writing my RUN commands with bash sets which has helped in quick debugging on failed builds. I thought I’d share to compare with other people’s habitual formats.

RUN bash -xec "command 1 \
    && command 2 \
    && ..."

Since this post I found something arguably better since it requires less code…

RUN set -x -e;\

Last update (I promise). I found out docker already addressed this issue. This method technically adds a layer but It didn’t add any size to my final image.

SHELL ["/bin/bash", “-xec”]
RUN cmd1; \