Skip to content
Latchkey

Docker "COPY failed: no source files specified" - Fix COPY/ADD

A COPY or ADD resolved to zero files. The pattern is valid but nothing in the build context matches it.

What this error means

The build fails on a COPY/ADD step with no source files were specified, even though the path looks correct. Other steps build fine up to that point.

docker build output
ERROR: failed to solve: COPY dist/* /app/: no source files were specified
# the dist/ directory is empty, missing, or excluded by .dockerignore

Common causes

A glob matches nothing

A pattern like COPY dist/* fails if dist/ is empty or was never built. Unlike a literal path, an empty glob is treated as "no source files".

The path is excluded by .dockerignore

A broad .dockerignore rule can exclude exactly the files you are trying to copy, so they are not in the context BuildKit sees.

The artifact was not produced before COPY

In a single-stage or mis-ordered build, the files are generated by a step that has not run (or runs outside the image), so the context lacks them.

How to fix it

Confirm the files exist in the build context

List what the context actually contains and check .dockerignore.

Terminal
ls -la dist/                 # does it exist and have files?
grep -n dist .dockerignore   # is it excluded?

Build artifacts in an earlier stage and copy across

Generate the files inside the image (multi-stage) so they are guaranteed present.

Dockerfile
FROM node:20 AS build
WORKDIR /app
COPY . .
RUN npm ci && npm run build      # produces dist/

FROM nginx:alpine
COPY --from=build /app/dist /usr/share/nginx/html

How to prevent it

  • Generate artifacts inside the build (multi-stage) instead of relying on host files.
  • Keep .dockerignore narrow enough not to exclude copied paths.
  • Fail the build early if a required directory is empty.

Related guides

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