COPY vs ADD in Dockerfile: Which Should You Use?
Best practices for copying files into Docker images. Why COPY is almost always preferred over ADD.
COPY package.json package-lock.json ./Step-by-Step Execution Guide
COPY src/ /app/src/COPY only performs straightforward local file copying from host context into the image layer.
ADD archive.tar.gz /opt/ADD automatically unpacks recognized compressed tar archives (gzip, bzip2, xz) into the destination directory.
COPY --chown=node:node . /appSets file user and group ownership during copy without requiring a separate "RUN chown -R" layer.
Critical Docker Pitfalls & Precautions
- β’Do not use "ADD <remote-url>". It is better practice to use "RUN curl -fsSL <url> | tar -xz" to avoid leaving uncompressed cache files in image layers.
COPY vs ADD Differences - Frequently Asked Questions
Common questions about container isolation, signal handling, and runtime behavior.
COPY is transparent and predictable. ADD has implicit behaviors (tar extraction, remote URL fetching) that can introduce security risks and unexpected build errors.
Related Docker Command Guides
Browse All Docker RecipesOpen an interactive terminal shell session inside a live running Docker container to inspect files, debug processes, or test network connectivity.
Reclaim gigabytes of hard drive space by removing stopped containers, unused networks, dangling images, and build caches.
Instantly stop all active containers and optionally remove them with a single command.
Copy files or directories between a Docker container and your local host file system without creating a volume mount.
Understand the fundamental differences between ENTRYPOINT and CMD directives and how to combine them for flexible container CLIs.
Inspect stdout and stderr output from containers with timestamps, tail line limits, and live streaming.