构建 docker 映像时是否可以显示“WORKDIR"? [英] Is it possible to show the `WORKDIR` when building a docker image?
问题描述
我们在构建 docker 映像时遇到了 WORKDIR
问题.是否可以打印 WORKDIR
的值?
We have a problem with the WORKDIR
when we building a docker image. Is it possible to print the value of WORKDIR
?
我们试过了:
ECHO ${WORKDIR}
但是没有这样的指令ECHO
推荐答案
在构建过程中,Docker 没有内置的方法来打印 WORKDIR
.您可以检查图像/图层的最终工作目录:
There's no builtin way for Docker to print the WORKDIR
during a build. You can inspect the final workdir for an image/layer:
docker image inspect {image-name} | jq '.[].Config.WorkingDir'
可以通过打印 shells 默认工作目录来查看 Linux 容器构建步骤 workdir:
It's possible to view a Linux containers build steps workdir by printing the shells default working directory:
RUN pwd
或者shell经常将工作目录存放在PWD环境变量中
or the shell often stores the working directory in the PWD environment variable
RUN echo "$PWD"
如果您使用的是较新版本的 dockers BuildKit,则需要使用 --progress=plain
If you are using newer versions of dockers BuildKit, stdout will need to be enabled with --progress=plain
docker build --progress=plain .
这篇关于构建 docker 映像时是否可以显示“WORKDIR"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!