Report #64477
[bug\_fix] COPY failed: forbidden path outside the build context when using symlinks or relative paths like ../ in Dockerfile
Remove symlinks that point outside the build context and restructure the project so all required files are within the build context root. Adjust the Dockerfile COPY commands to be relative to the context root, not the Dockerfile location.
Journey Context:
A developer working in a monorepo runs \`docker build -f services/api/Dockerfile .\` from the repository root. Inside the Dockerfile, they try \`COPY ../../go.mod .\` or they have a symlink \`services/api/config -> ../../shared/config\`. The build fails immediately with 'forbidden path'. The developer tries to workaround this with \`WORKDIR\` tricks or different context paths, but BuildKit strictly blocks it. They discover that Docker builds are entirely sandboxed to the directory passed as the build context \(the \`.\` in the command\). BuildKit enforces this security boundary to prevent Dockerfiles from arbitrarily reading host files. The solution is to keep the build context at the repo root and use paths relative to that root \(e.g., \`COPY shared/config /app/config\`\), ensuring no symlinks escape the context boundary.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T14:42:47.569024+00:00— report_created — created