Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Docker

Docker: COPY vs ADD — What’s the Difference?

- 20.06.26 - ErcanOPAK

📄 COPY is Simple. ADD has Extra Features.

Both copy files into image. COPY is simple file copy. ADD can download URLs and extract archives. Use COPY unless you need ADD features.

📦 COPY (Simple)

COPY app.js /app/
COPY src/ /app/src/
COPY --chown=user:group file /app/

📦 ADD (Extra Features)

ADD https://example.com/file.tar.gz /app/
ADD archive.tar.gz /app/  # Auto-extract
ADD --chown=user:group file /app/

🎯 Best Practices

# ✅ Use COPY for local files
COPY package.json package-lock.json ./
COPY src/ ./src

# ✅ Use ADD for remote files (rare)
ADD https://example.com/cert.pem /app/cert.pem

# ✅ Use ADD for archive extraction (rare)
ADD archive.tar.gz /app/  # Automatically extracts

# ❌ Don't use ADD for local files (use COPY)
ADD app.js /app/  # Works but COPY is preferred

# ❌ Don't use COPY for remote files (use ADD)
COPY https://example.com/file /app/  # Doesn't work!

# Why COPY is preferred:
# - Clear intent (only copies files)
# - Build cache works better
# - No unexpected extraction

💡 Summary

  • COPY: Use for local files (preferred, clear intent)
  • ADD: Use for remote URLs or archive extraction
  • Both support –chown to set ownership
  • ADD auto-extracts tar.gz, tar, zip (avoid unexpected behavior)
  • Docker best practice: prefer COPY unless you need ADD features

“Used ADD everywhere. ADD extracted a tar.gz unexpectedly, broke my build. Switched to COPY for local files, ADD only for downloads. Now builds are predictable.”

— Docker User

Related posts:

Docker: Add Health Checks to Detect and Restart Failing Containers

Docker: Add Health Checks to Detect Unhealthy Containers

Docker: Why You Should COPY package.json BEFORE the Rest of Your App

Post Views: 1

Post navigation

Kubernetes: Understand Service Types — ClusterIP, NodePort, LoadBalancer
AI Prompt: Generate Structured Meeting Agendas

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

July 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  
« Jun    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (898)
  • How to make theater mode the default for Youtube (857)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (814)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (597)
  • Add Constraint to SQL Table to ensure email contains @ (582)
  • Average of all values in a column that are not zero in SQL (545)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (512)
  • Find numbers with more than two decimal places in SQL (460)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes
  • Ajax: Use Axios for HTTP Requests
  • JavaScript: Understand Hoisting
  • HTML: Use Web Storage for Client-Side Data
  • CSS: Use Filter Effects for Visual Magic
  • Windows 11: Unlock God Mode for All Settings

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (898)
  • How to make theater mode the default for Youtube (857)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (814)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com