Home › Docker

COPY failed: file not found in build context — how to fix

=> ERROR [3/5] COPY ../config/app.conf /etc/app/
failed to solve: failed to compute cache key: failed to calculate checksum of ref: "/config/app.conf": not found

Quick fix: Paths in COPY are relative to the build context, not the Dockerfile. Build from a parent folder with -f: docker build -f app/Dockerfile . and use COPY config/app.conf /etc/app/. Also check .dockerignore.

What it means

docker build . sends the contents of . (the build context) to the builder. COPY and ADD can only see files in that context. They can't reach ../ or absolute host paths.

Cause 1: file is outside the context

project/
  config/app.conf
  app/Dockerfile      # COPY ../config/app.conf ...  ← not allowed

Build from the parent and point to the Dockerfile:

cd project
docker build -f app/Dockerfile -t myapp .
COPY config/app.conf /etc/app/
COPY app/ /src/

docker-compose:

services:
  app:
    build:
      context: .
      dockerfile: app/Dockerfile

Cause 2: .dockerignore excludes it

cat .dockerignore

Patterns like *, *.conf, config/ or **/*.json remove files from the context. Add an exception with !:

*
!src/
!package.json
!config/app.conf

Cause 3: wrong path or case

Paths are case-sensitive in Linux builds even on Mac/Windows: COPY Package.json won't find package.json. List what the builder actually receives:

docker build --no-cache --progress=plain -f - . <<'EOF2'
FROM busybox
COPY . /ctx
RUN find /ctx -maxdepth 3
EOF2

Cause 4: file is generated by a previous step you didn't run

COPY dist/ ... fails if you didn't build dist/ before docker build. Run the build first, or build inside the image with a multi-stage Dockerfile.

Cause 5: COPY --from with the wrong path

In multi-stage builds, COPY --from=builder /app/dist ./dist must use the absolute path inside the builder stage. Check the builder's WORKDIR.

Last updated 2026-10-29.