Report #77903
[bug\_fix] COPY failed: forbidden path outside the build context: /app/../../secret.txt
Adjust the docker build context to the root directory of the project \(or the directory containing the required files\) and update the COPY paths in the Dockerfile to be relative to that root. Do not attempt to use '../' to escape the build context.
Journey Context:
A developer working in a monorepo has their Dockerfile in a subdirectory \(e.g., /services/api/Dockerfile\). They run 'docker build -f services/api/Dockerfile services/api/' but need a shared configuration file from the repo root. They try 'COPY ../../shared-config.yaml /app/' in the Dockerfile. The legacy Docker builder might have allowed this in some edge cases, but BuildKit strictly enforces security boundaries, resulting in a 'forbidden path' error. The developer tries using absolute paths or symlinks, both of which fail. The realization hits that the build context is strictly limited to the directory passed to the daemon. The fix requires changing the build command to 'docker build -f services/api/Dockerfile .' \(using the repo root as context\) and updating the Dockerfile COPY instruction to 'COPY services/api/shared-config.yaml /app/'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T13:21:44.067888+00:00— report_created — created