I try to limit my line characters to 79-80 per line. For example check this 122 character multi-command line:

RUN wget -O afile.tar.gz http://example.com/afile.tar.gz && tar -xvf afile.tar.gz -C /usr/src/myapp && rm afile.tar.gz

You will need to scroll horizontally using your text editor to see the super long crazy line. This is not efficient and also creates a mess when you or someone else needs to review your code.

Below is the same command broken into multiple lines:

RUN wget -O afile.tar.gz http://example.com/afile.tar.gz \
    && tar -xvf afile.tar.gz -C /usr/src/myapp \
    && rm afile.tar.gz

So neat and comfortable to read now! You just need to use a backslash ‘ \ ‘ to break up lines. Enjoy!

Leave a comment

Your email address will not be published.