COPY failed: forbidden path outside the build context: ../file
A COPY/ADD tries to read a file above the build context (../something); Docker only sends the context folder to the builder.
Seen on:
Docker
Meaning
The build context is the directory passed to docker build. Anything outside it is invisible. Move the Dockerfile’s context up a level and use -f, or copy the files into the context first.
Common causes
- COPY ../shared /app/shared in the Dockerfile
- Monorepo: building a package from its own folder while it needs root files
- Symlinks pointing outside the context
⚡ Quick fix
- Build from the parent: docker build -f app/Dockerfile .
- Compose: context: .. with dockerfile: app/Dockerfile
- Copy the files into the context in a pre-build step
Detailed fix by platform
Docker Compose
- bash
services: api: build: context: .. dockerfile: api/Dockerfile
How to diagnose
- Context — Which folder is passed to build?
- Paths — Any ../ in COPY/ADD?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- COPY failed COPY failed: file not found in build context / "/app/x": not found
- did not complete successfully failed to solve: process "/bin/sh -c ..." did not complete successfully: exit code: 1
- failed to read dockerfile failed to solve: failed to read dockerfile: open Dockerfile: no such file or directory
Most viewed in Docker
Other ways to find it
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026