---
title: "Docker Best Practices: Understanding the Differences Between ADD and COPY Instructions in Dockerfiles"
description: "Dockerfile COPY only copies files and directories from the build context into an image layer."
url: "https://swe.quest/articles/docker-best-practices-understanding-the-differences-between-add-and-copy-4a75b284bd6c2baa"
canonical: "https://www.docker.com/blog/docker-best-practices-understanding-the-differences-between-add-and-copy-instructions-in-dockerfiles/"
source: "Docker"
published: "2024-08-08"
difficulty: "medium"
kind: "How-to"
reading_minutes: 6
tags: ["containers","supply-chain-security"]
---

# Docker Best Practices: Understanding the Differences Between ADD and COPY Instructions in Dockerfiles

A post on [Docker](https://swe.quest/sources/docker.md), published 2024-08-08, 6 min read, How-to. Original: [https://www.docker.com/blog/docker-best-practices-understanding-the-differences-between-add-and-copy-instructions-in-dockerfiles/](https://www.docker.com/blog/docker-best-practices-understanding-the-differences-between-add-and-copy-instructions-in-dockerfiles/)

## Summary

Dockerfile COPY only copies files and directories from the build context into an image layer. ADD can do the same, but it also downloads URLs and automatically extracts local and remote archives. That extra behaviour brings flexibility, but also unpredictability and security risk from external content, so COPY is the sensible default and ADD should be reserved for cases that need fetching or extraction. Both instructions also work with remote build contexts such as Git repositories, remote tarball URLs and OCI images, with COPY still scoped to the context.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Containers](https://swe.quest/tags/containers.md) (Infrastructure)
- [Supply chain security](https://swe.quest/tags/supply-chain-security.md) (Security)

## Prerequisites

- Dockerfile basics
- docker build ([easy posts on Containers](https://swe.quest/tags/containers.md?difficulty=easy))

## Keywords

Docker, Dockerfile, COPY, ADD, OCI images, build context

## Related posts

- [Introducing Docker Build Checks: Optimize Dockerfiles with Best Practices](https://swe.quest/articles/introducing-docker-build-checks-optimize-dockerfiles-with-best-practices-2400d0a2e13e5604.md): Docker · 2024-07-29 · Medium · 6 min read · Containers, Static analysis, CI/CD, Developer tools
  Docker Desktop 4.33 adds Build checks, which evaluate Dockerfiles against codified best-practice rules during \`docker build\` and report warnings.
- [Master Docker and VS Code: Supercharge Your Dev Workflow](https://swe.quest/articles/master-docker-and-vs-code-supercharge-your-dev-workflow-6114b48c12630cac.md): Docker · 2025-04-03 · Medium · 9 min read · Containers, Developer tools, Developer productivity, CI/CD
  Docker containers paired with VS Code's Docker extension give every developer an identical environment and remove "works on my machine" bugs.
- [Deploying to production in \<5m with our hosted container builder](https://swe.quest/articles/deploying-to-production-in-5m-with-our-hosted-container-builder-ca80279668d29e71.md): incident.io · 2021-11-18 · Medium · 9 min read · CI/CD, Containers, Build systems, Developer productivity, Caching
  incident.io cut Docker image build times from an inconsistent 3–10+ minutes back to under 2 minutes by replacing CircleCI's remote Docker and Docker Layer Caching with a permanently running GCP c2-standard-8 builder with a 500GB SSD.
- [How to Create Dockerfiles with GenAI](https://swe.quest/articles/how-to-create-dockerfiles-with-genai-c43e5eb0c85107c1.md): Docker · 2024-07-29 · Medium · 7 min read · AI agents, Containers, LLMs, Developer tools
  Framing Dockerfile generation as an interaction between an LLM and tools, rather than a chat where the user supplies project details, produces much better results.
- [Docker Best Practices: Using ARG and ENV in Your Dockerfiles](https://swe.quest/articles/docker-best-practices-using-arg-and-env-in-your-dockerfiles-97d31347b92062d6.md): Docker · 2024-10-16 · Medium · 6 min read · Containers, Configuration management
  ARG defines variables available only during the image build, while ENV defines variables available at build time and at container runtime.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
