如何在Dockerfile中为ENTRYPOINT指定工作目录 [英] How to specify working directory for ENTRYPOINT in Dockerfile
问题描述
Docker映像(基于Windows)包括位于 C:\App
的应用程序目录。该目录中包含几个子文件夹和文件,其中包括一个名为 process.bat
的批处理文件。 Dockerfile(用于构建映像)的结尾如下:
The Docker image (Windows-based) includes an application directory at C:\App
. Inside that directory reside several sub-folders and files, including a batch file called process.bat
. The Dockerfile (used to build the image) ends like this:
ENTRYPOINT [ "C:\\App\\process.bat" ]
当我使用以下命令实例化此图像时: docker运行company / app
,批处理文件运行,但是在引用 C:\App
下的其他文件时失败。从本质上讲,工作目录仍然是Docker容器入口点的 C:\
。
When I instantiate this image using the command: docker run company/app
, the batch file runs, but it fails at the point where other files under C:\App
are referenced. Essentially, the working directory is still C:\
from the Docker container's entry-point.
在Dockerfile中设置工作目录的方法?确实有几种选择:
Is there a way to set the working directory within the Dockerfile? Couple of alternatives do exist:
- 将
-w C:\App
添加到docker run - 在批处理文件中,我可以在
cd / DC:\App
- Add
-w C:\App
to the docker run - In the batch file, I can add a line at the beginning
cd /D C:\App
但是可以在Dockerfile中指定工作目录吗?
But is there a way to specify the working directory in the Dockerfile?
推荐答案
WORKDIR / App
是可在dockerfile中使用的命令,以更改工作目录。
WORKDIR /App
is a command you can use in your dockerfile to change the working directory.
这篇关于如何在Dockerfile中为ENTRYPOINT指定工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!