docker path_handling ai_generated true

COPY failed: file not found — Dockerfile COPY with spaces in path

ID: docker/copy-space-in-path-failure

Also available as: JSON · Markdown
90%Fix Rate
92%Confidence
4Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
24 active

Root Cause

Dockerfile COPY instruction fails when source or destination path contains spaces without proper quoting.

generic

Workarounds

  1. 95% success Use JSON array form for COPY with paths containing spaces
    COPY ["src/my file.txt", "/app/my file.txt"]  # JSON array form handles spaces correctly

    Sources: https://docs.docker.com/reference/dockerfile/#copy

  2. 82% success Rename files to remove spaces before COPY, or use .dockerignore and a staging step
    RUN mv '/app/my file.txt' /app/my_file.txt  # normalize after copy

    Sources: https://docs.docker.com/reference/dockerfile/#copy

Dead Ends

Common approaches that don't work:

  1. Escape spaces with backslash in COPY instruction 75% fail

    Backslash escaping is inconsistent across Docker versions and platforms

  2. Use shell glob to match the file with spaces 85% fail

    COPY does not expand shell globs the same way; glob matching is for ADD with URLs only