douxu4610
2015-09-21 03:32
浏览 100
已采纳

Docker-compose golang-无可构建源

I've followed a couple of tutorials and am having trouble figuring out what i've done wrong. I suspect its a very basic principal but that said as i'm new to both GoLang and docker-compose i'm not 100% sure which is my problem.

I'm running the golang:build docker image which just retrieves a couple github repositories.

Any help would be much appreciated.

The error is as follows:

+ exec go get -v -d
can't load package: package app: no buildable Go source files in /go/src/app
Service 'ddd' failed to build: The command '/bin/sh -c go-wrapper download' returned a non-zero code: 1

The Docker-Compose file looks like this

ddd:
  build: ./goSvc
  working_dir: /go/src/
  command: go run main.go
  volumes:
    - ./goSvc/src/main.go:/go/src/main.go
    - ./goSvc/src/ddd:/go/src/ddd
  ports:
    - 8080:8080
  environment:
    - DB_NAME=rnse
    - DEBUG=true

Go project structure

root
  goSvc
    pkg
    src
      ddd
        internal
          logic
        ...myGoFiles
      github.com
      main.go
    Dockerfile

Edit: Including docker file for golang:

FROM golang:onbuild
RUN go get github.com/gorilla/mux
RUN go get github.com/lib/pq
EXPOSE 8080

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

我遵循了一些教程,但在弄清楚我做错了什么时遇到了麻烦。 我怀疑它是一个非常基本的原理,但是那是因为我对GoLang和docker-compose都是新手,所以我不是100%确定这是我的问题。

我正在运行 golang:build docker image仅检索几个github仓库。

任何帮助将不胜感激。

错误如下:

  + exec go get -v -d 
无法加载软件包:软件包app:/ go / src / app 
中没有可构建的Go源文件服务'ddd'构建失败 :命令'/ bin / sh -c go-wrapper download'返回了非零代码:1 
   
 
 

Docker-Compose文件如下所示

  ddd:
构建:./goSvc
 working_dir:/ go / src / 
命令:运行main.go 
卷:
-./goSvc/  src / main.go:/go/src/main.go 
-./goSvc/src/ddd:/go/src/ddd
端口:
-8080:8080 
环境:
-DB_NAME =  rnse 
-DEBUG = true 
   
 
 

转到项目结构

  root 
 goSvc 
 pkg 
  src 
 ddd 
内部
日志 ic 
 ... myGoFiles 
 github.com 
 main.go 
 Dockerfile 
   
 
 

编辑: 包括用于golang的docker文件:

 从FROM golang:onbuild 
RUN转到github.com/gorilla/mux
RUN转到github.com/lib/pq
EXPOSE 8080 
   \  n 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongtuoao7987 2015-09-22 08:51
    已采纳

    Image you used is used to automatically build Go app when building initial image.

    Have a look at it's Dockerfile. There is ONBUILD COPY . /go/src/app statement.

    So you can either locate Dockerfile where main.go is located or use image without ONBUILD trigger and then run go run manually/with docker-compose.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题