Docker构建因本地go软件包导入而失败 [英] Docker build fails with local go package import

查看:109
本文介绍了Docker构建因本地go软件包导入而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个go应​​用程序,其中包含一个主程序包和一个身份验证程序包。身份验证包将导入到主文件中。目录结构如下,

I have built a go application which has a main package and an authentication package. The authentication package is imported in main file. The directory structure is as follows,

docker文件的内容如下,

and the docker file contents are as follows,

FROM golang

COPY ./  /Users/venkat/go/src/github.com/Athavankanapuli/interflow_api/loginservice/app
WORKDIR  /Users/venkat/go/src/github.com/Athavankanapuli/interflow_api/loginservice/app
RUN go get github.com/go-kit/kit/endpoint
RUN go get golang.org/x/oauth2
RUN go get github.com/go-kit/kit/endpoint
RUN go get gopkg.in/mgo.v2/bson 
RUN go install ./...
RUN go build 

EXPOSE 8080
CMD [ "./app" ]

泊坞窗正确地完成了所有导入操作,但无法读取身份验证包。
$ GOPATH 是指 / Users / venkat / go
终端命令 docker build -t interflow。以下错误输出,

The docker does all the imports properly but it fails to read the authentication package. The $GOPATH refers to /Users/venkat/go The terminal command docker build -t interflow . gives the following error output,

如何修复这个错误,并使本地身份验证程序包被包含在构建中?还是有其他更好的方法来编写用于正确构建的dockerfile?

How to fix this error and make the local authentication package gets included in the build? Or is there any other better way of writing the dockerfile for the proper build?

推荐答案

容器和构建环境将无权访问笔记本电脑的环境变量。 使用图像的记录方式使用/ go / src目录:

The container and build environment will not have access to your laptop's environment variables. The documented way to use the image uses the /go/src directory:

FROM golang:1.8

WORKDIR /go/src/app
COPY . .

RUN go-wrapper download   # "go get -d -v ./..."
RUN go-wrapper install    # "go install -v ./..."

CMD ["go-wrapper", "run"] # ["app"]

我相信以上所述将对您有用,并且是所有情况下的最佳选择,尽管我的工作有点生疏。

I believe the above would work for you and would be the best option of all, though my go is a little rusty.

您可以定义 $ GOPATH 在Dockerfile中带有 ENV GOPATH = / Users / venkat / go 。但是,与其设置环境变量,不如建议使用图像假定的GOPATH值:

You could define the $GOPATH with an ENV GOPATH=/Users/venkat/go in your Dockerfile. However instead of setting the environment variable, I'd recommend instead using the value of the GOPATH assumed by the image:

FROM golang:1.9

COPY .  /go/src/github.com/Athavankanapuli/interflow_api/loginservice/app
WORKDIR  /go/src/github.com/Athavankanapuli/interflow_api/loginservice/app
RUN go get github.com/go-kit/kit/endpoint
RUN go get golang.org/x/oauth2
RUN go get github.com/go-kit/kit/endpoint
RUN go get gopkg.in/mgo.v2/bson 
RUN go install ./...
RUN go build 

EXPOSE 8080
CMD [ "./app" ]

这篇关于Docker构建因本地go软件包导入而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆