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'
Related Docker job interview questions
What is the ENV instruction good for in Docker?
Docker SeniorWhat is the ENTRYPOINT instruction good for in Docker?
Docker SeniorWhat is the RUN instruction good for in Docker?
Docker SeniorAre ARG variables persisted into the built images in Docker?
Docker SeniorYou have a variable declared using ARG and the same variable declared using ENV instruction in your Dockerfile. What variable value will be used?
Docker Senior