Copy instruction
The Dockerfile COPY instruction copies files or directories from a build context or another build stage into an image’s filesystem.
Learn Docker in a Month of Lunches, Second Edition
A COPY instruction is a Dockerfile directive that copies files or directories into the image filesystem.
- How it is used
- Places application files into Docker images, including source files for builds and compiled artifacts for final stages.
- How deep it goes
- Defines source and target paths, then works through copy ordering, multi-stage copying, and image-size consequences.
- Examples
- Uses a Node.js application file, a Maven-built JAR, and a comparison between copying an entire directory and copying only its app folder.
- What you can do after
- Build it from scratch: write COPY instructions that place needed files in an image while avoiding unnecessary copied content.
Read how Learn Docker in a Month of Lunches, Second Edition explains copy instruction →
Podman in Action: Secure, rootless containers for Kubernetes, microservices, and more
The COPY directive adds files, directories, or archive contents from the build host to the image filesystem.
- How it is used
- Adds build-context content to an image filesystem while constructing a Podman image.
- How deep it goes
- Explains sources, destinations, rootfs population, and practical builds, but defers detailed path and archive semantics.
- Examples
- Uses index.html copied into an HTTP server document root and shows the resulting podman build output.
- What you can do after
- Build it into an image by placing files in a context directory and invoking podman build.
Also covered in
- Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform
- Build Financial Software with Generative AI (From Scratch)
- Road to Kubernetes
- Machine Learning Platform Engineering
- Build Python Web Apps with Streamlit
What to know first
- containerA software container is an isolated execution environment that packages an application and its dependencies, typically sharing the host operating-system kernel.
- package.jsonpackage.json is the standard JSON manifest for an npm or Node.js package, declaring metadata, dependencies, scripts, entry points, and related configuration.
- port numberA port number is a transport-layer identifier associated with a host address that directs network traffic to a service or application endpoint.
Related concepts
- file systemuses · A file system is a software-managed structure and set of operations for organizing, naming, storing, and accessing files and directories on storage.
- Dockerfileused by · A Dockerfile is a text file containing instructions for building a Docker container image.
- context directoryuses · A context directory is a directory containing the files and build instructions made available to a container image build.
- instructionkind of · An instruction is a directive specifying an action, operation, task, constraint, or expected behavior for a person or computational system.
Questions about copy instruction
What is copy instruction?
The Dockerfile COPY instruction copies files or directories from a build context or another build stage into an image’s filesystem.
Which Manning books explain copy instruction?
Learn Docker in a Month of Lunches, Second Edition and Podman in Action: Secure, rootless containers for Kubernetes, microservices, and more.
What should I know before learning copy instruction?
Manning books that teach copy instruction usually introduce container, package.json and port number first.
What is the difference between copy instruction and ADD?
The Dockerfile COPY instruction copies files or directories from a build context or another build stage into an image’s filesystem. ADD is a Dockerfile instruction that copies files or directories into a container image and can also retrieve files from remote URLs.
What is copy instruction a kind of?
Copy instruction is a kind of instruction. An instruction is a directive specifying an action, operation, task, constraint, or expected behavior for a person or computational system.
What is copy instruction also called?
Copy instruction is also called COPY command or COPY directive.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

