How COPY and ADD Resolve Relative Paths on Windows
On Windows with Docker Desktop, the COPY and ADD instructions look up paths relative to the build context you hand to docker build. When a path like ../../a/b/c gets rewritten to /a/b/c, the host can no longer find the file. The simplest fix is to move the file you need into the build context directory and then point to it from there in your Dockerfile.
- Move the file that sits outside the context into the build context path.
- Point to that file from the context path when copying it into the image.
- Keep in mind that resources must be public and reachable from the build directory.
Other Questions Developers Ask
Other common questions cover how to include files outside Docker's build context, how to grab a value from Jenkins console output and post it to Slack, how to build a lazy string with an address, how to redirect between Django apps, how to handle duplicated cardviews with SwipeRefreshLayout, how to build an Android library in Android Studio, the jmxterm "Unable to create a system terminal" error, how to extract files from a Jenkins container, how to use Vue CLI3 with Electron, and whether the AWS RDS free tier resets each month.
To explore more developer discussions, head back to the home page.
Keeping the files you need inside the build context avoids the path-rewriting surprises that COPY and ADD can cause on Windows. Once the file lives in the context, referencing it from your Dockerfile is straightforward and portable.
