Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to show the `WORKDIR` when building a docker image?

We have a problem with the WORKDIR when we building a docker image. Is it possible to print the value of WORKDIR?

We tried:

ECHO ${WORKDIR} 

But there is no such instruction ECHO

like image 993
Freewind Avatar asked Jun 13 '16 05:06

Freewind


People also ask

Does Docker create Workdir?

If the WORKDIR command is not written in the Dockerfile, it will automatically be created by the Docker compiler. Hence, it can be said that the command performs mkdir and cd implicitly. If the project directory does not exist, it will be created.

What is Workdir in Docker image?

WORKDIR instruction is used to set the working directory for all the subsequent Dockerfile instructions. Some frequently used instructions in a Dockerfile are RUN, ADD, CMD, ENTRYPOINT, and COPY. If the WORKDIR is not manually created, it gets created automatically during the processing of the instructions.

Can we see the Docker image content?

You can run an interactive shell container using that image and explore whatever content that image has. The steps will be logged into the image_history file. Show activity on this post. Show activity on this post.

Can Dockerfile have multiple Workdir?

you can have multiple WORKDIR in same Dockerfile. If a relative path is provided, it will be relative to the previous WORKDIR instruction. If no WORKDIR is specified in the Dockerfile then the default path is / . The WORKDIR instruction can resolve environment variables previously set in Dockerfile using ENV.


1 Answers

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' 

It's possible to view a Linux containers build steps workdir by printing the shells default working directory:

RUN pwd 

or the shell often stores the working directory in the PWD environment variable

RUN echo "$PWD" 

If you are using newer versions of dockers BuildKit, stdout will need to be enabled with --progress=plain

docker build --progress=plain .  
like image 71
Matt Avatar answered Sep 20 '22 01:09

Matt