Report #74741
[bug\_fix] COPY failed: forbidden path outside the build context
Refactor the directory structure so all necessary files are within the build context root, or execute the build command from the parent directory using the -f flag to specify the Dockerfile. Alternatively, use BuildKit's --build-context feature to bind mount external directories.
Journey Context:
A developer tries to COPY ../shared\_config.yaml . to share a configuration file across multiple microservices in a monorepo. It works in their local scripts using legacy builder workarounds, but fails in CI with BuildKit enabled. They go down a rabbit hole trying to symlink the file or change working directories inside the Dockerfile using WORKDIR, only to find the same error. They eventually realize BuildKit strictly enforces security by forbidding paths traversing outside the build context \(../\). They fix it by moving the Docker build context root up to the parent directory and using -f service/Dockerfile ., or by adopting the newer BuildKit --build-context shared=../shared\_config.yaml syntax.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T08:03:04.521310+00:00— report_created — created