Report #75712
[bug\_fix] COPY failed: forbidden path outside the build context
Remove symlinks from the build context that point outside the directory, or copy the actual target files into the build context. Add the offending symlinks to .dockerignore.
Journey Context:
A developer has a monorepo where a frontend directory contains a symlink to a shared common folder at the repo root. The Dockerfile uses COPY . /app. It builds fine on their machine using the legacy builder, but when they switch to BuildKit \(or run it in a strict CI environment\), the build abruptly fails with forbidden path outside the build context. They initially suspect a Docker context configuration issue and try absolute paths, which fails differently. They dig into BuildKit security models and realize that BuildKit strictly resolves symlinks and enforces a security boundary: no file copied into the image can resolve to a path outside the initial build context tarball. The legacy builder was more permissive or handled the tar resolution differently. The fix is to either restructure the build so the context is at the repo root \(and adjust the Dockerfile path\), physically copy the shared code into the context, or use .dockerignore to exclude the symlink and find another way to share the code \(like multi-stage builds copying from a parent context\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:40:40.142388+00:00— report_created — created