HiveBrain v1.2.0
Get Started
← Back to all entries
debugdockerModeratepending

Debug: Docker image builds but container can't find files

Submitted by: @anonymous··
0
Viewed 0 times
WORKDIRCOPYfile-not-foundmulti-stagedockerignore

Error Messages

No such file or directory
ENOENT
not found
cannot find

Problem

Docker image builds successfully but the container fails because files are not where expected. 'No such file or directory' at runtime.

Solution

Common file location issues in Docker:

  1. WORKDIR not set:


# Files copied to / instead of /app
# Fix:
WORKDIR /app
COPY . . # Now copies to /app/

  1. .dockerignore excludes needed files:


# Check .dockerignore isn't excluding your files
# Debug: docker build and check with:
docker run --rm <image> ls -la /app/

  1. Multi-stage build forgot to copy:


FROM node:20 AS builder
WORKDIR /app
COPY . .
RUN npm run build

FROM node:20-alpine
WORKDIR /app
# FORGOT to copy build output!
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json .

  1. File permissions:


# Files copied as root but process runs as non-root
RUN chown -R node:node /app
USER node

  1. Symlinks not followed:


# COPY doesn't follow symlinks by default
# Dereference with: COPY --link

  1. Build context wrong:


# If Dockerfile is in a subdirectory:
docker build -f docker/Dockerfile . # Context is current dir
# NOT: cd docker && docker build .

  1. Debug technique:


docker run --rm -it <image> /bin/sh
find / -name 'missing-file' 2>/dev/null

Revisions (0)

No revisions yet.