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
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.
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.
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.
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.
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 .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With