COPY failed 🐳 Docker

COPY failed: file not found in build context / "/app/x": not found

The Dockerfile COPY refers to a path outside the build context, excluded by .dockerignore, or relative to the wrong directory.

Seen on: Docker

Meaning

Docker can only copy files from the build context — the directory you pass to docker build (often .). Paths are relative to that context, not to the Dockerfile, and .. can’t escape it.

Common causes

  • File excluded by .dockerignore
  • Build run from a different directory than expected (context path)
  • Path with ../ pointing outside the context
  • Case mismatch or file not committed in CI checkout
  • Compose build.context set to a subfolder

⚡ Quick fix

  1. Run the build from the project root: docker build -f docker/Dockerfile .
  2. Remove the path from .dockerignore (or add a !path exception)
  3. Move shared files inside the context or widen the context

Detailed fix by platform

Docker

  1. Compose with an explicit context:
    yaml
    services:
      api:
        build:
          context: .                 # project root = what COPY can see
          dockerfile: docker/api.Dockerfile

How to diagnose

  1. Context — Which directory is the build context?
  2. Ignore — Is the file matched by .dockerignore?
  3. Path — Is the COPY source relative to the context?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.