乐闻世界logo
搜索文章和话题

What is the difference between Docker COPY and ADD instructions?

2月17日 23:48

Both Docker COPY and ADD are used to copy files from the host to the image, but they have important differences. COPY can only copy local files and is simple and straightforward; ADD supports automatic extraction of compressed files (tar, gzip, bzip2, etc.) and downloading files from URLs. Best practice is to prefer COPY because its behavior is more predictable. While ADD's automatic extraction feature is convenient, it can lead to unexpected results. If you need to download files from URLs, it's recommended to use RUN wget or curl, so you can clean up the cache in the same layer. COPY syntax: COPY [--chown=:] ... .

标签:Docker