Use WORKDIR to switch to a directory
30 libjpeg-dev libjpeg-turbo8-dev libturbojpeg git-lfs ccache
31
32# Change into the user directory, download and unzip the github actions runner
33RUN cd /home/docker && mkdir actions-runner && cd actions-runner \34 && curl -O -L https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-arm64-${RUNNER_VERSION}.tar.gz \
35 && tar xzf ./actions-runner-linux-arm64-${RUNNER_VERSION}.tar.gz
36
Use WORKDIR to switch to a directory
30WORKDIR /home/docker
31
32# Change into the user directory, download and unzip the github actions runner
33RUN cd /home/docker && mkdir actions-runner && cd actions-runner \34 && curl -o actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz -L https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz \
35 && tar xzf ./actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz
36
Description
Only use cd
in a subshell. Most commands can work with absolute paths and in most cases, it is not necessary to change directories. Docker provides the WORKDIR
instruction if you really need to change the current working directory.
Also note that any changes to the environment or working directory within a RUN
command will not stay in effect in subsequent lines.
Bad Practice
FROM debian:buster
RUN cd /usr/src/app && git clone [email protected]:lukasmartinelli/hadolint.git
Recommended
FROM debian:buster
WORKDIR /usr/src/app
RUN git clone [email protected]:lukasmartinelli/hadolint.git