Docker:更改目录命令(Change directory command in Docker?)

编程入门 行业动态 更新时间:2024-10-26 19:35:26
Docker:更改目录命令(Change directory command in Docker?)

在码头我想做这个:

git clone XYZ cd XYZ make XYZ

但是由于没有cd命令,我必须每次都通过完整路径(使XYZ / fullpath)。 有什么好的解决方案吗?

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?

最满意答案

您可以对RUN运行脚本或更复杂的参数。 以下是我下载的Dockerfile的一个例子:

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

由于使用'&&',如果所有以前的命令都成功,它将只能进入最终的'pip install'命令。

实际上,由于每个RUN都会创建一个新的commit&(当前)一个AUFS层,如果在Dockerfile中有太多的命令,那么您将使用限制,因此合并RUN(当文件稳定时)可以是非常有用的事情要做

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.

更多推荐

本文发布于:2023-07-08 00:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1070188.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令   目录   Docker   command   directory

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!