Docker WORKDIR - 在我的机器上还是容器上?

标签 docker dockerfile

Dockerfile 中的 WORKDIR 关键字引用什么上下文?是在我正在生成的容器中或内部运行docker build的上下文中吗?

我发现自己经常将 RUN cd && ... 放入我的 docker 文件中,并希望有另一种方法,我觉得我错过了一些东西。

最佳答案

它在容器内。

取自 Dockerfile 引用站点 https://docs.docker.com/engine/reference/builder/#workdir

The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile. If the WORKDIR doesn’t exist, it will be created even if it’s not used in any subsequent Dockerfile instruction.

因此,您可以这样做,而不是添加 RUN cd && ...:

WORKDIR /path/to/dir
RUN command

关于Docker WORKDIR - 在我的机器上还是容器上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56956425/

相关文章:

ruby - 使用 Whenver 和 Rake 配置 Dockerfile 以运行 Cron 任务

docker 服务与撰写文件单节点和本地镜像

python - 模块导入错误,如何刷新Ipython session ?

docker - docker 是否使用主机的随机和时间同步

docker,mariadb 不是从 "init"开始,基于 debian :stable

php - Docker PHP - PECL 安装在使用 Heredoc 和 bash 时无法检测系统类型,但可以使用 SHELL 命令处理 shell 设置

Docker 构建 : runnable is in parent folder

jenkins - 在 Docker 中运行 Jenkins 时出错

python - requirements.txt 中的 Dask 数据框?

docker - 标记 Docker 图像 (SemVer)