如何在 Dockerfile 中为 ENTRYPOINT 指定工作目录 [英] How to specify working directory for ENTRYPOINT in Dockerfile

查看:45
本文介绍了如何在 Dockerfile 中为 ENTRYPOINT 指定工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 run 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/D C: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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆