Skip to content
Latchkey

Docker "ADD failed: stat ...: no such file or directory" in CI

An ADD instruction referenced a local file the builder could not find in the build context. The path resolves to nothing, so BuildKit cannot stat it.

What this error means

The build fails on an ADD step with ADD failed: stat ...: no such file or directory, naming a path under the build temp dir. Earlier steps built fine; the file the ADD wants is simply not in the context.

docker build output
ADD failed: stat /var/lib/docker/tmp/docker-builder123/config.tar:
no such file or directory

Common causes

The ADD source is not in the build context

The path is wrong relative to the context root, or the file lives above the context directory. ADD can only see files inside the context sent to the daemon.

Excluded by .dockerignore

A broad .dockerignore rule removed exactly the file the ADD references, so it never reaches the builder.

A generated artifact was not produced first

The file is created by a build step that runs outside the image (or has not run yet), so it does not exist when ADD looks for it.

How to fix it

Confirm the source exists in the context

List the file relative to the build context and check it is not ignored.

Terminal
ls -la config.tar              # exists in the context root?
grep -n config.tar .dockerignore   # not excluded?

Reference a path inside the context, or use a URL

ADD accepts a remote URL or a context-relative path - not an arbitrary host path outside the context.

Dockerfile
# context-relative file:
ADD ./build/config.tar /app/
# or a remote URL (ADD can fetch over HTTP):
ADD https://example.com/config.tar /app/

How to prevent it

  • Keep ADD/COPY sources inside the build context directory.
  • Maintain a narrow .dockerignore so needed files are not excluded.
  • Generate required artifacts before the build, or inside an earlier stage.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →