Having long RUN instruction on a single line reduce the visibility and make it harder to read and understand.

Why is this an issue?

In Dockerfiles, RUN instruction tend to be extensive and can rapidly become quite long, containing a lot of instruction with parameters and flags.
In order to keep a good readability and help for future maintenance, it is important to split them into multiple lines.
It is usually a good idea to group elements that belong together on the same lines.
The usage of the operator && allows to chain multiple operators. Also, the default operator \ allows to continue the RUN instruction on the next line.
Another way is to use the here documents format, which allows to define multiple instructions together without any chaining operator.

How to fix it

Code examples

Noncompliant code example

RUN apt-get update && apt-get install -y package-bar package-baz package-foo package-eel

Compliant solution

# Split shell form
RUN apt-get update && \
  apt-get install -y \
  package-bar \
  package-baz \
  package-foo \
  package-eel


# Heredoc form
RUN <<EOF
apt-get update
apt-get install -y \
    package-bar \
    package-baz \
    package-foo \
    package-eel
EOF

Resources

Documentation