ScanSkill

COPY

The COPY instruction is similar to ADD instruction. It copies new files or directories from <src> and adds them to the container filesystem at a path <dest>.

The only difference between COPY and ADD is: that COPY instruction doesn't copy content from remote URL

Syntax

COPY [--chown=<user>:<group>] <src>... <dest>
COPY [--chown=<user>:<group>] ["<src>",... "<dest>"]

NOTE: Here, --chown is only for Linux containers, and doesn’t work for Windows.

Example

  • To add all files from project root to destination file system path of image:
COPY . /path/to/image/filesystem/
  • To add all files starting with “clou”:
COPY clou* /cloudyfoxdir/
  • This ? will replace any single character like cloudy.txt:
COPY cloud?.txt /cloudyfoxdir/

Here, the destination is an absolute path or relative path to WORKDIR. Below is an example of a relative path and this will add cloudy.txt file to <WORKDIR>/relativeDir/:

COPY cloudy.txt relativeDir/

Similarly, the following example uses an absolute path and adds cloudy.txt file to /absoluteDir/:

COPY cloudy.txt /absoluteDir/