构建 docker 映像时是否可以显示“WORKDIR"?

编程入门 行业动态 更新时间:2024-10-11 07:32:35
本文介绍了构建 docker 映像时是否可以显示“WORKDIR"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们在构建 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"?

本文发布于:2023-10-27 04:27:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1532311.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:映像   docker   quot   WORKDIR

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!