Change directory command in Docker?

2019-01-16 13:17发布

In docker I want to do this:

git clone XYZ
cd XYZ
make XYZ

However because there is no cd command, I have to pass in the full path everytime (make XYZ /fullpath). Any good solutions for this?

标签: docker cd
3条回答
我命由我不由天
2楼-- · 2019-01-16 13:53
RUN git clone http://username:password@url/example.git
WORKDIR /folder
RUN make
查看更多
【Aperson】
3楼-- · 2019-01-16 13:55

To change into another directory use WORKDIR. All the RUN, CMD and ENTRYPOINT commands after WORKDIR will be executed from that directory.

RUN git clone XYZ 
WORKDIR "/XYZ"
RUN make
查看更多
聊天终结者
4楼-- · 2019-01-16 14:00

You can run a script, or a more complex parameter to the RUN. Here is an example from a Dockerfile I've downloaded to look at previously:

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

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

In fact, since every RUN creates a new commit & (currently) an AUFS layer, if you have too many commands in the Dockerfile, you will use up the limits, so merging the RUNs (when the file is stable) can be a very useful thing to do.

查看更多
登录 后发表回答