‹ All Docker Interview Questions questions

Docker Interview Question 7: Copy vs Add Archive

Docker Interview Questions · Test 1 · question 7 of 10

Dockerfile Instructionseasy

A Dockerfile contains ADD vendor.tar.gz /opt/vendor/, where vendor.tar.gz sits in the build context. Following a "prefer COPY over ADD" guideline, a teammate changes it to COPY vendor.tar.gz /opt/vendor/. The image builds, but the application now fails because /opt/vendor/ holds only the file vendor.tar.gz instead of the extracted libraries. Why?

Select one answer
Show answer and explanation

Answer:

  • D. ADD extracts a local tar archive automatically, while COPY copies the file as-is

ADD and COPY are functionally similar, but ADD has extra behaviour: when the source is a local tar archive in a recognized compression format (gzip, bzip2, xz, zstd, or uncompressed), it is decompressed and extracted into the destination. COPY does basic copying only, so the archive lands unchanged. To switch to COPY, extract the archive in a RUN step (or keep ADD on purpose for this line).

Option A is false: COPY copies single files as well as directories.

Option B is false: COPY reads from the build context by default. COPY --from is only an option for copying from another stage or image.

Option C is false: .dockerignore removes files from the build context itself, so excluded files are invisible to *both* instructions.

References: Dockerfile reference - ADD; Building best practices - ADD or COPY

Practice Test 1 ›

Study guides for Docker Interview Questions