Change command directory in Docker?

In docker, I want to do this:

git clone XYZ cd XYZ make XYZ 

However, since there is no cd command, I have to go the full path each time (make XYZ / full path). Any good solutions for this?

+128
docker cd
Dec 17 '13 at 10:55
source share
3 answers

You can run a script or a more complex parameter for the RUN. Here is an example from a Docker file that I downloaded to view earlier:

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

Due to the use of '& &', it will only get to the final 'pip install' command if all previous commands succeed.

In fact, since each RUN creates a new commit and (currently) AUFS level, if you have too many commands in the Docker file, you will use limits, so combining RUN (when the file is stable) can be a very useful thing.

+89
Dec 17 '13 at 11:13
source share

To change directory, use WORKDIR . All RUN, CMD, and ENTRYPOINT commands after WORKDIR will be executed from this directory.

 RUN git clone XYZ WORKDIR "/XYZ" RUN make 
+333
Nov 04 '14 at 3:20
source share
 RUN git clone http://username:password@url/example.git WORKDIR /folder RUN make 
+21
Jul 07 '16 at 20:37
source share



All Articles