Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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 local machine. Or is it the same meaning of . in most console commands like essentially selecting all in the current directory.

COPY somecode.java .  #copy the rest of the code  COPY . . 

The . also seems to mean find the docker file in the current directory.

docker build -t image-tag . 
like image 758
Kode Avatar asked Mar 07 '19 01:03

Kode


People also ask

What is Docker current working directory?

WORKDIR. It's a directory inside your container image that can be set with the WORKDIR instruction in the Dockerfile. It is optional (default is / , but base image might have set it), but considered a good practice. Subsequent instructions in the Dockerfile, such as RUN , CMD and ENTRYPOINT will operate in this dir.

What is the default working directory for Docker?

The default is indeed / as stated elsewhere. It is worth mentioning, though, that you will almost never be running from an empty docker image ( FROM scratch ), so the WORKDIR is likely set by the base image you're using.

What does image mean in Docker?

A Docker image is a file used to execute code in a Docker container. Docker images act as a set of instructions to build a Docker container, like a template. Docker images also act as the starting point when using Docker. An image is comparable to a snapshot in virtual machine (VM) environments.

What does from mean in Dockerfile?

The FROM instruction specifies the Parent Image from which you are building. FROM may only be preceded by one or more ARG instructions, which declare arguments that are used in FROM lines in the Dockerfile .


2 Answers

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.

like image 81
Andreas Lorenzen Avatar answered Oct 12 '22 04:10

Andreas Lorenzen


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.

like image 24
Trần Đức Tâm Avatar answered Oct 12 '22 05:10

Trần Đức Tâm