What’s the difference between COPY and ADD in a Dockerfile, and when should you use each?

I’m trying to understand the real distinction in the docker ADD vs COPY debate. Both seem to copy files into the container, but are there specific use cases or features—like handling URLs or tar files—where one is preferred over the other?

I remember hitting this early when I was just getting into Docker. Here’s the thing with the whole docker add vs copy discussion: use COPY by default. It’s simpler. COPY just copies files or directories, nothing more, no surprises. ADD adds a few extra powers like unpacking tarballs or fetching remote URLs, which sounds handy at first. But honestly, that behavior can be a little too ‘magical’ and lead to confusion later. Unless you need those features, COPY keeps your Dockerfile predictable and clean

Yeah, that mirrors my experience too. I’ve worked on several microservices projects, and when it comes to docker add vs copy, I treat ADD as a tool for edge cases. Need to download something during the build or unpack a local archive on the fly? Sure, ADD works. But its automatic extraction can trip you up if you’re not expecting it. I’ve seen teams confused when files ‘suddenly’ appear unpacked. So as a rule of thumb, I default to COPY for clarity and consistency, it keeps builds repeatable and easier to debug.

Totally agree with both of you. After working with Docker for years across CI/CD pipelines, I’ve realized the real distinction in docker add vs copy comes down to developer intent. COPY is explicit, it just says, ‘Put this file here.’ ADD, on the other hand, leaves room for interpretation,‘maybe copy, maybe download, maybe extract.’ That ambiguity can save you time when used right, like pulling in a compressed dataset and having it unpack itself automatically. But for regular use? I want to avoid any unexpected behavior, so COPY is my go-to 99% of the time.