In a Dockerfile, for each command, 'RUN' executes in a new shell; thus, 'cd' alone will not keep the change to the working directory for other commands. There are, however, two workarounds for this limitation:
Use the WORKDIR Command
The WORKDIR command lets you change the working directory for further commands in the Dockerfile. You can use it in the following format:
WORKDIR /path/to/your/directory # Change to your directory
RUN git clone XYZ # Clone the repository
WORKDIR XYZ # Change to cloned directory
RUN make # Run make
Run Several Commands in One 'RUN' Command
If you dislike changing the working directory too many times, you can run all your commands in one 'RUN' command:
RUN git clone XYZ && \
cd XYZ && \
make
For such a case, 'cd' is relevant only within the chain of commands because it's chained with both 'git clone' and 'make,' thus succeeding in its task.
Set Full Paths using Environment Variables
If you really abhor entering full paths you could define an environment variable to hold the path of the cloned directory:
ENV REPO_DIR /path/to/your/directory/XYZ
RUN git clone XYZ $REPO_DIR && \
cd $REPO_DIR && \
Make