Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Docker 6 min read How-to mediumAdept

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

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.

Assumes: Dockerfile basicsdocker build

Related posts

  • Introducing Docker Build Checks: Optimize Dockerfiles with Best Practices

    Docker mediumAdept

    Docker Desktop 4.33 adds Build checks, which evaluate Dockerfiles against codified best-practice rules during `docker build` and report warnings. Because the checks are part of the build itself, they also consider build arguments and base images rather than only linting the text. `docker build --check` runs the evaluation in under a second without executing the build, and `# check=error=true` makes warnings fail CI. Individual rules can be disabled with `# check=skip=...`, and the checks also work with multi-stage builds, Bake and Docker Build Cloud.

  • Master Docker and VS Code: Supercharge Your Dev Workflow

    Docker mediumAdept

    Docker containers paired with VS Code's Docker extension give every developer an identical environment and remove "works on my machine" bugs. The walkthrough builds and runs annotated Dockerfiles for an Express app and a Flask app, then manages containers from the extension's sidebar. It also covers attaching the debugger to Node's inspect port (9229) and to multiple services under Compose, and using Dev Containers for shared team environments. Tips include trusted base images, scanning with Docker Scout or Trivy, `.dockerignore` and multi-stage builds, and a GitHub Actions snippet that builds, tests and pushes images.

  • Deploying to production in <5m with our hosted container builder

    incident.io mediumAdept

    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. The slow builds came from CircleCI's DLC attaching a cache disk only when one is free, so concurrent builds often started with a cold layer cache. Larger CircleCI resource classes added minutes of provisioning time. CircleCI jobs now reach the dedicated daemon over SSH via DOCKER_HOST. Measured builds take 20s with no changes and about 1m50s when both the Go backend and React frontend change, for roughly £350/month.

  • How to Create Dockerfiles with GenAI

    Docker mediumAdept

    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. An assistant given analyze_project, write_files and docker_scout_tag_recommendation functions, two anchoring instructions, and Markdown best-practice prompts for NPM projects generates a three-stage Dockerfile with current slim base images and npm cache mounts, instead of an outdated single-stage node:14 file. The full transcript shows the GPT-4 assistant recovering on its own from an invalid-JSON tool error. Docker is still testing whether this approach adapts to new project types more easily than code templates.

  • Docker Best Practices: Using ARG and ENV in Your Dockerfiles

    Docker mediumAdept

    ARG defines variables available only during the image build, while ENV defines variables available at build time and at container runtime. Worked examples show ARG values overridden with --build-arg or Compose build args. ENV cannot be declared without a value, so runtime values come from docker run -e, --env-file, or Compose environment interpolation via the shell, an inline variable, or a .env file. Rule of thumb: use ARG for build-only values and ENV for anything needed at runtime.

The quest for software engineering knowledge.

Look:
Layout: