Docker add folder into image
我有从根项目运行的Docker文件,它工作正常现在,我需要将本地计算机中的项目添加到图像中,我按照以下步骤进行了操作
1 | ADD ../proj1 /go/src/proj1 |
现在我得到了错误
1 2 | Step 7/16 : ADD ../proj1 /go/src/proj1 ADD failed: Forbidden path outside the build context: ../proj1 () |
我怎样才能克服这个问题?我不想把
Docker文件上的所有其他路径都正常
1 2 3 4 5 | 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 |
为了建造它,我跑步
1 | docker build -t myproj . |
答案是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.