Report #96911
[bug\_fix] COPY failed: forbidden path outside the build context
Move the Dockerfile to the root of the project \(or higher directory\), adjust the \`docker build\` context path, and update the COPY paths accordingly. Alternatively, use BuildKit's \`--build-context\` flag to bind mount external directories. You cannot COPY files from outside the build context root.
Journey Context:
A developer is working in a monorepo with a structure like \`services/api/\` and \`shared/libs/\`. They place a Dockerfile in \`services/api/\` and run \`docker build .\` from that directory. They attempt to \`COPY ../../shared/libs /app/libs\` to include shared code. The build immediately fails with a 'forbidden path' error. The developer tries absolute paths, which also fail. They spend time checking file permissions and symlinks, thinking it's an OS-level access issue. Finally, they realize Docker strictly enforces that the build context \(the directory passed to the docker daemon, usually \`.\`\) is the root filesystem for COPY commands. The daemon cannot reach the parent directory \`../\` by design. The fix requires running the build from the monorepo root \(\`docker build -f services/api/Dockerfile .\`\) and changing the Dockerfile to \`COPY shared/libs /app/libs\`, or using the BuildKit specific \`--build-context=shared=../../shared/libs\` and \`COPY --from=shared . /app/libs\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T21:14:54.283703+00:00— report_created — created