Docker "failed to solve: WORKDIR creates invalid path" in CI
A WORKDIR must resolve to a directory. When a component of the path already exists as a file or symlink to a non-directory, BuildKit cannot mkdir through it and the solve fails with creates an invalid path.
What this error means
A build fails at a WORKDIR instruction with creates an invalid path. A parent component of the WORKDIR exists as a file rather than a directory.
docker
ERROR: failed to solve: WORKDIR /app/bin creates an invalid path: /app/bin is not a directoryCommon causes
A path component already exists as a file
If /app/bin was created as a file (e.g. copied as a single binary), WORKDIR /app/bin/sub cannot make a directory under it.
A symlink in the path points at a non-directory
A WORKDIR whose parent is a symlink to a file resolves to an invalid directory target.
How to fix it
Use a path whose components are all directories
- Pick a WORKDIR that does not collide with an existing file.
- Create binaries under a directory rather than at the WORKDIR path itself.
Dockerfile
# bin is a file here, so this fails:
# COPY app /app/bin
# WORKDIR /app/bin/run
# use distinct paths:
COPY app /app/bin/app
WORKDIR /app/workRemove the conflicting file before WORKDIR
- Delete or rename the file occupying the path.
- Then set the WORKDIR.
Dockerfile
RUN rm -f /app/bin
WORKDIR /app/binHow to prevent it
- Keep WORKDIR paths distinct from file destinations.
- Avoid symlinking path components to non-directories.
- Name copied binaries explicitly rather than reusing a directory path.
Related guides
Docker "WORKDIR requires absolute path" - Fix Relative WORKDIR in CIFix Docker build "the working directory ... must be an absolute path" / surprising relative WORKDIR behavior…
Docker "failed to solve: cannot copy to non-directory" in CIFix Docker build "failed to solve: cannot copy to non-directory" in CI - a COPY of multiple files (or a direc…
Docker "failed to solve: cannot replace to directory with file" in CIFix BuildKit "failed to solve: cannot replace to directory with a file" in CI - a COPY/ADD tries to write a f…