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 .
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.
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.
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.
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 .
The .
simply means "current working directory"
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
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.
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>
".
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With