Sobes.tech
Junior — Middle

What is the role of the ADD command in a Dockerfile and how does it differ from COPY?

sobes.tech AI

Answer from AI

The ADD command in a Dockerfile is used to copy files and directories from the build context into the Docker image. Unlike COPY, ADD supports additional features:

  • It can automatically unpack local archives (e.g., .tar, .tar.gz) when adding.
  • It can download files from URLs and add them to the image.

However, due to these extra features, ADD can behave less predictably, so it is recommended to use COPY for simple file copying, and ADD only when unpacking or URL downloading features are needed.

Example usage:

# Copies a local file
COPY ./app /app

# Adds and unpacks an archive
ADD ./archive.tar.gz /app

# Downloads a file from a URL
ADD https://example.com/file.txt /app/file.txt