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.
error building image: error building stage: failed to execute command: resolving src:
copy failed: stat /kaniko/buildcontext/app/requirements.txt: no such file or directoryCommon 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
- Confirm where the COPY source lives relative to the Dockerfile.
- Point
--contextat the directory that contains those sources. - Point
--dockerfileat the Dockerfile path within that context.
/kaniko/executor \
--context dir://${CI_PROJECT_DIR} \
--dockerfile ${CI_PROJECT_DIR}/app/Dockerfile \
--destination registry.example.com/app:latestCheck .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 - make sure this does not exclude COPY sources
**/node_modules
!app/requirements.txtHow to prevent it
- Pin
--contextand--dockerfileexplicitly 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.