Docker的工作目录是什么意思?
阿神
阿神 2017-04-24 09:11:18
0
5
829

在Docker compose 的yml文件中,
有个参数叫工作目录,即:working_dir,
什么工作在“工作目录”进行?
百度了一下没找到很好的解释。

阿神
阿神

闭关修行中......

reply all(5)
阿神

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

If you knew its full spelling, you wouldn’t have this problem.

The full spelling of pwd is "print working directory".


Then let’s talk about this parameter in docker compose.

I didn’t know there was a working_dir in docker compose before I saw the question. My first thought was the same as one of the answers above, which is the WORKDIR in the Dockerfile. The meaning of WORKDIR is naturally to switch the current directory to the specified path.

But the original poster was right, and then I thought that the compose file is actually another form of docker run command line configuration, so it is very likely that docker run also has this attribute.

Just docker run --help and find that there is a "-w, --workdir Working directory inside the container" parameter.

Sure enough, this is the parameter used to set the working path when docker run. Then I searched for this attribute in compose, Googled it, and found Docker’s official documentation:

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.

小葫芦

The format is WORKDIR /path/to/workdir.
Configure the working directory for subsequent RUN, CMD, and ENTRYPOINT instructions.

For example
WORKDIR /home/docker/

Commands executed later will be in the /home/docker/ directory by default

For example: vim key.json
The actual path of this file is /home/docker/key.json

大家讲道理

Similar to the current directory on the command line

小葫芦

Equivalent to linux…cd WORKDIR

伊谢尔伦

Owner, once the problem is solved, let’s close it. Someone answered on 3.25...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template