请注意,我是Golang和Docker开发的新手。我已经在其他地方问过这个问题,并试图阅读文档,但是找不到任何解决方案。
我有两个存储库/home/experience/keep-ecdsa
和/home/experience/keep-core
,它们是从this project分叉并在本地克隆的。
我正在尝试在本地为keep-ecdsa
构建一个docker镜像。这是指向我的forked repo的链接。
有一些keep-core
依赖项,我想指向我的本地keep-core
回购。因此,我将go.mod
更改为:
module github.com/keep-network/keep-ecdsa
go 1.13
replace (
//unrelated stuff...
github.com/keep-network/keep-core => /home/experience/keep-core
)
require (
//unrelated stuff...
github.com/keep-network/keep-core v1.1.3
)
DOCKERFILE的启动过程如下(click here to see the full file):
FROM golang:1.13.8-alpine3.10 AS runtime
ENV APP_NAME=keep-ecdsa \
BIN_PATH=/usr/local/bin
FROM runtime AS gobuild
ENV GOPATH=/go \
GOBIN=/go/bin \
APP_NAME=keep-ecdsa \
APP_DIR=/go/src/github.com/keep-network/keep-ecdsa \
BIN_PATH=/usr/local/bin \
# GO111MODULE required to support go modules
GO111MODULE=on
//rest of the linked DOCKERFILE
运行docker build .
时,出现下面的错误,该错误发生在RUN go mod download
的{{1}}步骤中。
DOCKERFILE
Step 13/27 : RUN go mod download
--> Running in 88839fc42d4e
go: github.com/keep-network/keep-core@v1.1.3: parsing /home/experience/keep-core/go.mod: open /home/experience/keep-core/go.mod: no such file or directory
The command '/bin/sh -c go mod download' returned a non-zero code: 1
更改为各种绝对本地fs路径GOPATH
在DOCKERFILE中指向我的绝对本地路径APPDIR
/home/experience/keep-ecdsa
的{{1}}语句中的路径更改为各种路径(相对于replace ( )
的绝对本地路径,等等您位于
go.mod
基本图片中 所以里面没有GOPATH
因为那只在你本地的fs上
但是我仍然不知道如何实现我想要的水。也许用某些本地基本映像替换DOCKERFILE中的golang:1.13.8-alpine3.10
语句?但是我如何找到这样相关的基本映像,并且不会更改其余的DOCKERFILE指令?
请记住,我将对/home/experience/keep-core
依赖项进行本地更改,并且需要对其进行测试,因此包含在FROM ... AS runtine
中的解决方案并不令人满意。
谢谢。
答案 0 :(得分:1)
您位于golang:1.13.8-alpine3.10基本映像内,因此其中没有/ home / experience / keep-core,因为那只在您本地的fs上
根据我在文件中看到的,您尚未将机器上的/home/experience/keep-core
目录复制到docker映像,因此由于该目录尚不存在,它引发了错误。
Docker无法跟踪当前上下文目录之外的链接,因此,如果您不想编辑replace (github.com/mygithubprofile/keep-core)
,则可以将DockerFile移至/home/experience/
并使用COPY
命令来复制{ {1}}文件夹从本地计算机到docker镜像。
keep-core
但是,如果要将DockerFile保留在RUN mkdir -p /home/experience/keep-core
COPY ./keep-core /home/experience/keep-core
中,则可以将/home/experience/keep-ecdsa
文件夹移到keep-core
文件夹中,而在keep-ecdsa
文件中将其忽略。然后更新
.gitignore
TO
replace (
//unrelated stuff...
github.com/keep-network/keep-core => /home/experience/keep-core
)