简体   繁体   English

如何在文件夹中运行docker命令

[英]How to RUN docker commands inside a folder

How using a Dockerfile can I RUN all commands within a folder home? 如何使用Dockerfile可以RUN文件夹主目录中的所有命令?

For example, in Docker I have the following where I have to CD into the folder before running the second command: 例如,在Docker中,我需要执行以下命令,在运行第二个命令之前,将CD放入文件夹:

RUN cd /var/sites/demo && virtualenv env --system-site-packages
RUN cd /var/sites/demo && pip install -r requirements.txt

Is there a way I can remove the cd /var/sites/demo and have each command run from that location? 有什么方法可以删除cd /var/sites/demo并从该位置运行每个命令?

By setting WORKDIR to the appropriate path: 通过将WORKDIR设置为适当的路径:

From the Dockerfile Reference : Dockerfile Reference

The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile. WORKDIR指令为Dockerfile中跟在其后的所有RUN,CMD,ENTRYPOINT,COPY和ADD指令设置工作目录。

So your file should have: 因此,您的文件应具有:

WORKDIR /var/sites/demo

Before your RUN commands. 在您的RUN命令之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM