How can you split a long RUN instruction on multiple lines in Dockerfile?

Experience Level: Senior
Tags: Docker

Answer

In the shell form you can use a \ (backslash) to continue a single RUN instruction onto the next line. For example, consider these two lines:

RUN /bin/bash -c 'source $HOME/.bashrc; \
echo $HOME'

Together they are equivalent to this single line:

RUN /bin/bash -c 'source $HOME/.bashrc; echo $HOME'

Comments

No Comments Yet.
Be the first to tell us what you think.
Docker instructions
Docker instructions

Are you learning Docker ? Try our test we designed to help you progress faster.

Test yourself