Skip to content
Latchkey

Kaniko "error building stage: no such file or directory" in CI

Kaniko executed a Dockerfile instruction (usually COPY or ADD) whose source path is not present in the context Kaniko unpacked. The path is relative to --context, and a wrong context or a .dockerignore exclusion makes the file invisible.

What this error means

Kaniko stops with "error building image: error building stage: failed to execute command: resolving paths: ... no such file or directory". The named path exists in your repo but not in the context Kaniko received.

kaniko
error building image: error building stage: failed to execute command: resolving src:
copy failed: stat /kaniko/buildcontext/app/requirements.txt: no such file or directory

Common causes

The --context points at the wrong directory

Kaniko resolves COPY sources relative to --context. If the context is the repo root but the file is under a subfolder (or vice versa), the path does not exist where Kaniko looks.

The file is excluded by .dockerignore

A .dockerignore entry drops the file from the packed context, so Kaniko never sees it even though it is in the repo.

How to fix it

Set --context and --dockerfile to match the layout

  1. Confirm where the COPY source lives relative to the Dockerfile.
  2. Point --context at the directory that contains those sources.
  3. Point --dockerfile at the Dockerfile path within that context.
Terminal
/kaniko/executor \
  --context dir://${CI_PROJECT_DIR} \
  --dockerfile ${CI_PROJECT_DIR}/app/Dockerfile \
  --destination registry.example.com/app:latest

Check .dockerignore is not dropping the file

Confirm the source path is not matched by a .dockerignore pattern; Kaniko honors it just like a daemon build.

.dockerignore
# .dockerignore - make sure this does not exclude COPY sources
**/node_modules
!app/requirements.txt

How to prevent it

  • Pin --context and --dockerfile explicitly instead of relying on defaults.
  • Keep .dockerignore reviewed so it never drops files a COPY needs.
  • Use paths relative to the context, not the repo root, in COPY instructions.

Frequently asked questions

What causes ""error building stage ... no such file or directory""?
Kaniko resolves COPY sources relative to --context. If the context is the repo root but the file is under a subfolder (or vice versa), the path does not exist where Kaniko looks.
How do I fix "error building stage ... no such file or directory"?
Set --context and --dockerfile to match the layout

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card