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

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.


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.

Tags:

Docker