Home > Net >  what is the purpose of the command "COPY ./ ." in Linux?
what is the purpose of the command "COPY ./ ." in Linux?

Time:03-19

I just saw a command when built a docker image as below

COPY ./ .

I know the parameter "./" which used in Linux or Unix to execute a complied program in the current directory. And the parameter "." present the current directory.

I just confused what is the real purpose of the command "COPY ./ ."?

Copy the current directory content to current directory?

Thanks for your help.

CodePudding user response:

This is a Docker command, not a Linux command.

From the Docker manual:

The COPY instruction copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest>.

The purpose is to copy all files from the build context (usually the directory on the host that contains the Dockerfile) into the container.

(For reference, the GNU/Linux command to copy files is cp)

CodePudding user response:

1: Copy the current directory content to current directory?

No, absolutely NOT

2: What is COPY ./ . ?

The COPY instruction takes at least two arguments. The last argument is the destination, and all other arguments are source files

Syntax: COPY [<src> | <src>] <dest>

COPY ./ .
      ^ ^         
      | |_ #=> place the file where the image is being built, into the build container
      |
    copy all files from HOST current dir

3: what is the real purpose of the command "COPY"?

  • The COPY instruction will copy files (say your source code, or hello program) from the filesystem where the image is being built, into the build container.
  • Related