问题描述
在 docker 中我想这样做:
In docker I want to do this:
git clone XYZ
cd XYZ
make XYZ
但是因为没有 cd 命令,我每次都必须传入完整路径(make XYZ/fullpath).对此有什么好的解决方案吗?
However because there is no cd command, I have to pass in the full path everytime (make XYZ /fullpath). Any good solutions for this?
推荐答案
您可以运行脚本,或者将更复杂的参数传递给 RUN.这是我之前下载的 Dockerfile 中的一个示例:
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
因为使用了'&&',如果前面的所有命令都成功了,它只会进入最后的'pip install'命令.
Because of the use of '&&', it will only get to the final 'pip install' command if all the previous commands have succeeded.
事实上,由于每次 RUN 都会创建一个新的 commit &(目前)一个AUFS层,如果你在Dockerfile中有太多的命令,你会用完限制,所以合并RUNs(当文件稳定时)是一个非常有用的事情.
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.
这篇关于在 Docker 中更改目录命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!