Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (2.3k points)

I want to use these with docker:

git clone XYZ
cd XYZ
make XYZ

But I can't as the cd command is not there. I do not wish to make xyz as the full path everytime, are there any workarounds?

1 Answer

0 votes
by (6.9k points)

Easy ! Just use the WORKDIR command to change the directory you want to. Any other commands you use beyond this command will be executed in the directory you have set. 

Here's an example:

RUN git clone XYZ 
WORKDIR "/XYZ"
RUN make

It is also a better practice to make use of WORKDIR in docker.

OR

You can do this by using a much more complex RUN command, like given below:

RUN cd /opt && unzip treeio.zip && mv treeio-master treeio && \
    rm -f treeio.zip && cd treeio && pip install -r requirements.pip

And this way it only gets to the last command [ pip install ] only if the previous commands were successfully executed.

Combining the different RUN commands is recommended. This is because every time RUN command is executed an AUFS layer and a new commit are created and there is a limit for them, so be careful about them.

Hope that helped :)


If you are looking for help from professional DevOps engineers who work with docker, try out docker training course.

Browse Categories

...