What does . mean in docker? Does it mean the current working directory of the image or the local machine?

前端 未结 4 1225
误落风尘
误落风尘 2021-01-04 09:43

I am confused about whether . means that it\'s a shortened abbreviation of the current directory of the image or if it\'s the current working directory on the l

相关标签:
4条回答
  • 2021-01-04 10:07

    The . simply means "current working directory"

    docker build

    In the context of the docker build command, you are using it to signal that the build context for docker build is the current working directory. Like so:

    docker build -t mytag:0.1 .
    

    Let's say that you have this structure:

    /home/me/myapp/
    ├── Dockerfile
    ├── theapp.py
    

    And you invoke the docker build command from /home/me/myapp - you will pass the current working directory as the build context. This means that docker will see the following filestructure when building:

    /
    ├── Dockerfile
    ├── theapp.py
    

    Dockerfile

    In the context of a Dockerfile, it means that same. Both inside and outside the image.

    Take this COPY instruction for example:

    COPY . /app
    

    Here the . means the current working directory, where the docker build command is executed. This will be relative the to build context that is passed to the docker build command.

    For this COPY instruction:

    COPY theapp.py .
    

    It means, take the file theapp.py and copy it to the working directory of the docker image that is being built. This directory can be set at build time with the WORKDIR instruction, so that:

    WORKDIR /app
    COPY theapp.py .
    

    Would leave you with the file /app/theapp.py inside the resulting docker image.

    Finally, this COPY instruction:

    COPY . .
    

    Means take everything from the working directory where the docker build command is issued, relative to the build context that is passed to it. And copy it to the current working directory of the docker image.

    0 讨论(0)
  • 2021-01-04 10:10

    I saw 3 . characters on your question, so let me expand one by one.

    The first, as you imagine, the . character means the current directory.

    In your Dockerfile

    COPY . .
    

    The second dot represented the current location on your virtual machine. Whenever you run cd command in the Dockerfile. That may be easy to understand.

    The first dot more unintelligible a little. The first dot character represented the current location on your host machine. The location you input after docker build command like that:"docker build [options] <location>".

    Docker build command

    The dot character means the current directory whenever you call your docker build command. For example:

    [~]$ docker build .

    The dot character represented for default home directory of this user on your real machine.

    0 讨论(0)
  • 2021-01-04 10:20

    .(dot) means current working directory.

    0 讨论(0)
  • 2021-01-04 10:21

    It depends on the context. In your COPY somecode.java . it's the image. In COPY . . it's both. The first dot is in the local machine and the second dot is the image.

    In the docker build command, it tells Docker to take files for the newly built image from the working directory on your local machine.

    As others said, it's basically just means "current working directory". But when building a Docker image, there are two of those. One in your local machine where you're building the image. The second one is the file system that's built in the image.

    0 讨论(0)
提交回复
热议问题