docker build COPY failed — no such file or directory

# The build context is the directory you pass to docker build
# Files must exist within the build context

# Run build from the directory containing your files
docker build -t my-image .

# Check what is in the build context (before Docker sees it)
# List files that would be included
cat .dockerignore
COPY failed: file not found in build context or excluded by .dockerignore:
stat app/package.json: file does not exist

Docker's COPY instruction can only reference files inside the build context. If the file is outside the context path, or listed in .dockerignore, it will not be visible.

Check .dockerignore is not too aggressive

# .dockerignore
node_modules
dist
.git
# Make sure you are not ignoring files you need to COPY

Widen the build context

Pass a parent directory as the context and specify the Dockerfile location with -f:

# Build context is parent dir; Dockerfile is in ./app/
docker build -f app/Dockerfile -t my-image ..

Correct COPY paths

# Copies ./src from the host build context to /app/src in the image
COPY src/ /app/src/

# NOT this — path must be relative to build context, not your machine
# COPY /home/user/project/src/ /app/src/   ← WRONG