Docker - Security - Use COPY instead of ADD

Arbitrary URLs specified for ADD could result in MITM attacks, or sources of malicious data.

In addition, ADD implicitly unpacks local archives which may not be expected and result in path traversal and Zip Slip vulnerabilities.

Use COPY, unless ADD is specifically required.


Docker provides two commands for copying files from the host to the Docker image when building it: COPY and ADD. The instructions are similar in nature, but differ in their functionality:

While subtle, the differences between ADD and COPY are important. Be aware of these differences to avoid potential security issues: