Home  >  Q&A  >  body text

Docker的工作目录是什么意思?

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

阿神阿神2759 days ago820

reply all(5)I'll reply

  • 阿神

    阿神2017-04-24 09:13:18

    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.

    reply
    0
  • 高洛峰

    高洛峰2017-04-24 09:13:18

    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

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-24 09:13:18

    Similar to the current directory on the command line

    reply
    0
  • 高洛峰

    高洛峰2017-04-24 09:13:18

    Equivalent to linux…cd WORKDIR

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-24 09:13:18

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

    reply
    0
  • Cancelreply