arrow_back
Back

Dockerfile COPY: copying files from the build context

Andrew Dorokhov Andrew Dorokhov schedule 1 min read

COPY copies files from the build context into the image filesystem — similar to the Unix cp command.

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

Two forms: COPY source dest and COPY ["source", "dest"]. The JSON array form is required when paths contain spaces. Wildcards can match multiple files or directories.

The <src> path must be inside the build context — you cannot copy from outside it (e.g., ../another_dir/myfile is invalid).

If <src> is a directory, the entire directory contents are copied, including filesystem metadata. If <src> is a file and <dest> ends with /, it is treated as a directory.

Examples:

# Copying files:
COPY home.txt /mydir/

# Copying a directory:
COPY folder /mydir/folder/
code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Dockerfile CMD: default container command

arrow_forward