'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
Solution 1:[1]
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:[2]
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:[3]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | ethergeist |
| Solution 3 |
