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/