-1

i've docker file which I run from my root project and it working ok Now I need to add project from my local machine to the image and I did it like following

ADD  ../proj1 /go/src/proj1

Now I got error

Step 7/16 : ADD  ../proj1 /go/src/proj1
ADD failed: Forbidden path outside the build context: ../proj1 ()

How can I overcome this? I dont want to put the proj1 under my root project

all other path's on the docker files are ok

FROM golang:alpine as builder
WORKDIR /go/src/rootproj
ADD . /go/src/rootproj
RUN CGO_ENABLED=0 go build -ldflags '-extldflags "-static"' -o main .
ADD  ../proj1 /go/src/proj1

And to build it I run

docker build -t myproj .
stderr
  • 8,567
  • 1
  • 34
  • 50
  • 1
    Possible duplicate of [How to include files outside of Docker's build context?](https://stackoverflow.com/questions/27068596/how-to-include-files-outside-of-dockers-build-context) – svsd Aug 30 '18 at 20:25
  • @svsd - I've tried it and it doesnt help...any other idea? –  Aug 30 '18 at 20:29
  • There's no way out of having a copy of `proj1` inside the build context. Maybe you can include it as a Git submodule so it's not manually copied? Or you could build a separate Docker image out of proj1 and use it as one the base images when building the current project. Depends on what you're actually trying to achieve though. – svsd Aug 30 '18 at 20:43

1 Answers1

1

The answer is taken from here by Sjord...

The build actually happens in /tmp/docker-12345, so a relative path like ../relative-add/some-file is relative to /tmp/docker-12345. It would thus search for /tmp/relative-add/some-file, which is also shown in the error message. It is not allowed to include files from outside the build directory, so this results in the "Forbidden path" message.

Kevin Kopf
  • 13,327
  • 14
  • 49
  • 66