What does Docker’s working directory mean?

  docker, question

In dockcomposse’s yml file,
There is a parameter calledworking directoryThat is, working_dir.
What job is it“Working Directory”Proceed?
Baidu did not find a good explanation.

Do you know the pwd command under Linux? The one used to display the absolute address of the current path.

If you knew how to spell it all, you wouldn’t have this problem.

The full spelling of pwd is “print working directory.”


Then we’ll talk about this parameter in DockCompose.

Before I saw the question, I didn’t know there was a working_dir in docker compose. The first thought is the same as one of the above answers, which is the working dir in Dockerfile. The working dir naturally means that the current directory switches to the specified path.

However, the host made a definite statement, and then I realized that the compose file is actually another form of configuring the command line of docker run, so it is very likely that this attribute is also included in docker run.

With dockerrun-help, I found a “-w,-workdirworking directory inside the container” parameter.

Sure enough, this is the parameter used to set the working path when docker run. Then search this attribute in compose, Google once and found Docker’s official document:

working_dir, entrypoint, user, hostname, domainname, mem_limit, privileged, restart, stdin_open, tty, cpu_shares
Each of these is a single value, analogous to its docker run counterpart

Sure enough, the configuration in the compose file directly corresponds to the parameters behind docker run, and there should be a smiling face here.