COPY
What is COPY?
COPY: Copies files/directories from the build context into the image. The plain, predictable way to add your source code. COPY copies files and folders from the build context into a Docker image. It is the plain, predictable way to add your code, such as COPY src ./src. The order of COPY lines has a big effect on build speed. Docker caches each step, and a step is rebuilt when the files it copies change. Copy dependency files first, install dependencies, then copy the rest of the code. Then editing a source file does not trigger a full reinstall of every package.
Frequently asked questions about COPY
What should you keep in mind with COPY?
Pair it with a .dockerignore file that excludes .git, node_modules, vendor, local .env files and logs. That keeps images small and secrets out of them. Use --chown to set ownership during the copy instead of running a separate chown step, which would add another large layer to the image.
What does an example of COPY look like?
COPY package*.json ./ COPY src ./src At a glance
| Category | Docker |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |