Is it possible to show the `WORKDIR` when building a docker image?
DockerDockerfileDocker Problem Overview
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
Docker Solutions
Solution 1 - Docker
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 .
Solution 2 - Docker
There seems some recent change to the docker build
command, where it hides stdout
during the build process.
In short use DOCKER_BUILDKIT=0 docker build
to get the "old" behavior back.
Solution 3 - Docker
RUN doesn't print in my IDE console if I use docker-compose up
.
But CMD does. So try
CMD pwd
In case you have python in the image, this should also work
CMD ["python", "-c", "import os;print(os.getcwd())"]
Please note, only one, the last CMD command will be executed in the "container-run" phase. All others will be silently ignored. On the other side, there is a standard piping workaround:
CMD pwd && ls