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:

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:

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.

(reference)