Back to Browse

Docker Interview: Difference Between COPY and ADD | Tar Extract + URL Demo

24 views
Mar 20, 2026
4:13

๐Ÿšจ "What is the difference between COPY and ADD in Docker?" This is one of the most asked Docker interview questions at every level โ€” and most candidates either say "they do the same thing" or only know half the answer. In this video I'll explain exactly what COPY and ADD are, show you all the key differences, demonstrate ADD auto extracting a tar file, show ADD fetching a file directly from a URL and tell you exactly when to use each one so you can answer this question completely and confidently! โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” ๐ŸŽฏ WHY THIS DIFFERENCE MATTERS IN REAL PROJECTS Most developers use COPY and ADD interchangeably without understanding what makes them different. But in real production Dockerfiles this matters a lot. ADD has two powerful extra features that COPY does not have: โ†’ It can automatically extract tar archives into the container โ†’ It can fetch files directly from a remote URL But these extra features also make ADD less predictable and harder to reason about โ€” which is exactly why Docker best practices recommend using COPY in most cases and only reaching for ADD when you specifically need its extra capabilities. Understanding this distinction and explaining it clearly is what separates a candidate who knows Docker syntax from one who understands Docker deeply. โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” ๐Ÿ“Œ WHAT YOU WILL LEARN IN THIS VIDEO โœ… What is COPY instruction in Dockerfile and what it does โœ… What is ADD instruction in Dockerfile and what it does โœ… Key differences between COPY and ADD โœ… How ADD automatically extracts tar archives โ€” shown live โœ… How ADD fetches files directly from a remote URL โ€” shown live โœ… Why Docker best practices prefer COPY over ADD โœ… When to use COPY and when to use ADD in real projects โœ… How to answer this question confidently in Docker interviews โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” ๐Ÿ” WHO IS THIS VIDEO FOR This video is perfect for you if you are: ๐Ÿ‘‰ A DevOps engineer preparing for Docker interviews ๐Ÿ‘‰ A developer who writes Dockerfiles regularly ๐Ÿ‘‰ Someone preparing for CKA or CKAD certification exams ๐Ÿ‘‰ A backend engineer containerizing applications for the first time ๐Ÿ‘‰ Anyone who has been asked "difference between COPY and ADD" in an interview and gave an incomplete answer โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” ๐Ÿ’ก COPY VS ADD โ€” COMPLETE BREAKDOWN ๐Ÿ“‹ COPY โ†’ Copies files and directories from host to container โ†’ Simple, predictable and transparent โ†’ Only works with local files and directories โ†’ Cannot extract archives โ€” copies tar as is โ†’ Cannot fetch from remote URLs โ†’ Recommended by Docker best practices for most use cases โ†’ Easier to understand and debug in Dockerfiles Example use case: Copying your application source code into the container Copying config files into the image during build โž• ADD โ†’ Does everything COPY does plus two extra features โ†’ Feature 1 โ€” Automatically extracts tar archives ADD app.tar.gz /app/ extracts contents directly into /app/ โ†’ Feature 2 โ€” Can fetch files from remote URLs ADD https://example.com/file.txt /app/file.txt โ†’ Less predictable because of implicit extraction behaviour โ†’ URL fetching has no cache busting support โ†’ Not recommended for simple file copying โ€” use COPY instead โ†’ Use only when you specifically need tar extraction or URL fetch Example use case: Adding a compressed archive that needs to be extracted Fetching a remote config or binary during image build โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” โš™๏ธ WHAT IS COVERED IN THE LIVE DEMO In the hands on demo section of this video I have: โ†’ Used COPY to copy files into a Docker container โ†’ Used ADD to copy the same files showing identical behaviour โ†’ Created a tar archive and used ADD to auto extract it into container โ†’ Verified the extracted contents inside the running container โ†’ Used ADD to fetch a file directly from a remote URL into container โ†’ Verified the downloaded file inside the running container โ†’ Showed why COPY is preferred for simple file operations โ†’ Demonstrated exactly when ADD is the right choice to use This is exactly how COPY and ADD work in real production Dockerfiles and what interviewers expect you to demonstrate when asked about this topic. #Docker #DockerCOPYvsADD #DevOps #DockerInterview #Dockerfile #DevOpsInterview #DockerTutorial #ayushbuildstech #devops #devopsinterview #docker #devopsguide #devopstrainingvideos #kubernetes

Download

0 formats

No download links available.

Docker Interview: Difference Between COPY and ADD | Tar Extract + URL Demo | NatokHD