2019-02-13 18:25
浏览 69

去在docker中构建:/ go / bin中意外的二进制文件

According to this post: What does go build build?

go build builds the binary and leaves it in the current directory, while go install moves the binary into $GOPATH/bin.

This works on my machine like that. However, I have a Dockerfile:

FROM golang:latest
ADD . /go/src/myapp
WORKDIR /go/src/myapp
RUN go get .
RUN go build 
RUN ls /go/bin # shows myapp!!
ENTRYPOINT ["/go/bin/myapp"] #works!!

There should be no difference here. The expected result was that /go/bin was empty and the binary myapp would be /go/src/myapp/myapp Instead, I see that build is working like install, and the binary shows up in /go/bin. Why??

图片转代码服务由CSDN问答提供 功能建议


go build 构建二进制文件并将其保留在当前目录中, 而 go install 将二进制文件移到 $ GOPATH / bin 中。

这在我的机器上是这样的。 但是,我有一个Dockerfile:

  FROM golang:latest 
ADD。  / go / src / myapp 
WORKDIR / go / src / myapp 
RUN go获取。
RUN go build 
RUN ls / go / bin#显示myapp !! 
ENTRYPOINT [“ / go / bin / myapp”] #works!  !

这里应该没有区别。 预期的结果是 / go / bin 为空,二进制 myapp / go / src / myapp / myapp 看到该构建就像安装一样工作,并且二进制文件显示在/ go / bin中。 为什么?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongzan1970 2019-02-13 20:04

    The go get command is installing your package into /go/bin. If you dont want to install your current package then pass -d to stop after downloading your dependencies.

    The -d flag instructs get to stop after downloading the packages; that is, it instructs get not to install the packages.

    点赞 打赏 评论

相关推荐 更多相似问题