Junior
What is the difference between COPY and ADD commands in Docker?
sobes.tech AI
Answer from AI
COPY copies files or directories from the host's local filesystem into the Docker image's filesystem. The source must be relative to the build context.
ADD has similar functionality but can also:
- Copy files from a URL.
- Extract compressed archives (tar, gzip, bzip2) from the source into the destination directory.
In most cases, it is preferable to use COPY, as it is more predictable and explicitly performs only copying. ADD should be used when automatic downloading or unpacking functionality is required.
# Using COPY to copy a file from the build context
COPY app.py /app/app.py
# Using ADD to copy and unpack an archive
ADD https://example.com/archive.tar.gz /app/