COPY
The Dockerfile instruction that copies files from the build context into the image.
In more detail
Paths are relative to the build context, and each COPY creates a new layer. Copying only what the program needs keeps images small and caches effective.
Examples
COPY app.sh .COPY --chown=app:app app.py .COPY --from=builder /app/dist ./distCOPY --from=build /out/app /appCOPY --from=build /workspace/target/app.jar app.jarRelated terms
- Dockerfile — A text file of instructions, such as FROM, COPY and RUN, that tells Docker how to build an image.
- build context — The set of files you hand to docker build, usually the current directory given as the final dot.
- .dockerignore — A file listing paths to leave out of the build context, like .gitignore for Docker builds.
- ADD — The Dockerfile instruction that copies files like COPY, but can also fetch URLs and unpack local archives.
- build cache — Saved results of earlier build steps that a build tool, such as Docker, reuses when nothing a step depends on has changed.
- multi-stage build — A Dockerfile with several FROM stages, where later stages copy only what they need from earlier ones.
Related guides
Taught in
- Building and Pushing Container Images — Continuous Integration & Continuous Delivery Pipelines
- Container Images The Exam Way — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Minimal Base Images: Less To Attack — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Union Filesystems, Images And Writable Layers — Docker Architecture & Production Containers
- Run The Spine Service And Publish Its Port — Docker Architecture & Production Containers
- Build Context, Dockerignore And Your First Dockerfile — Docker Architecture & Production Containers
- FROM, WORKDIR, COPY And ADD — Docker Architecture & Production Containers
- RUN, SHELL And Efficient Layer Caching — Docker Architecture & Production Containers
- Multi Stage Builds, Targets And Build Secrets — Docker Architecture & Production Containers
- Minimal Bases, Non Root Users And Smaller Images — Docker Architecture & Production Containers
- Harden And Deliver The Complete Service Stack — Docker Architecture & Production Containers
- Containerization Architecture: Multi-Stage Dockerfiles — Production Full-Stack Engineering
- Shipping in Scratch and Distroless Images — Concurrent Systems Programming with Go
- Packaging Into A Container — Modern Java: Virtual Threads & High-Throughput Services
- Twelve Lines, Ten Warnings: Dockerfile Instructions And hadolint — Docker Certified Associate (DCA) Exam Prep
- One Edited File, Six Rebuilt Steps: Layers, Cache And Flat Images — Docker Certified Associate (DCA) Exam Prep
- Images Sprint: Eight Questions On Builds, Tags And Registries — Docker Certified Associate (DCA) Exam Prep
- Friday, Nine In The Morning: The Mock Exam And Its Report — Docker Certified Associate (DCA) Exam Prep
- Works On My Laptop: Images, Containers, Volumes And Networks — CompTIA Linux+ (XK0-006) Exam Prep