Dockerfile - WORKDIR?!?

Dockerfile uses a keyword “WORKDIR” - I don’t understand why it is required. Dockerfile is preparing a secluded system / docker image and it doesn’t know where to keep all the files. Docker can have its own home directory where it will keep all files copied. No need to specify a data which is useless.

Could someone please explain if I’m wrong?

I couldn’t understand the issue, but WORKDIR is not required. Why do you ask? The WORKDIR instruction just sets the path what following shell commands or COPY and ADD instructions should use as “current directory” inside the temporary builder container, and also what the current directory iwill be when you open a shell in the container started from the built image.

Is it that multiple Linux users whoever to connect to the container will use same “current directory” inside the container?

I recommend trying a Dockerfile with only a FROM and a WORKDIR instruction to see what it is for. Whoever has access to the docker daemon socket will also be able to instruct Docker through its API to execute a process in the container. The user on behalf of which the process will be executed is also controlled by an instruction in the Dockerfile, called “USER”. You can override the workdir and the user too when using docker exec to run anything in the container. Check the the output of docker exec --help for mor details.

WORKDIR specifies which internal directory the container will start processes from, as in, the path within the container, not on the host

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.