Why You Should Use COPY Instead of ADD When Building Docker Images

A report about Docker security has recently been published with actionable advice on how to further bridge the gap on docker images security. In this article, I'd like to visit one of these concerns and discuss the differences of COPY and ADD directives in a Dockerfile.

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:

This tip is part of a complete 10 Docker image security best practices you should adopt. Thanks for reading and to Omer Levi Hevroni who worked with me on it.

The original blog post includes a high-resolution printable PDF like the snippet you see below. Check it out

 

 

 

 

Top