英文:
docker-compose cannot find package
问题
我正在使用GO编写一个简单的应用程序,我有以下文件夹结构:
docker-compose.yml文件的内容如下:
version: '2'
services:
db:
image: rethinkdb:latest
ports:
- "38080:8080"
- "38015:28015"
- "39015:29015"
api:
image: golang:1.8-alpine
volumes:
- .:/go/src/test_server/
working_dir: /go/src/test_server
command: go run server.go
container_name: test_server
ports:
- "8085:8085"
links:
- db
tty: true
每次我运行docker-compose up时,都会收到以下错误消息:
> test_server | controllers/users.go:4:3: cannot find package
> "/go/src/test_server/vendor/github.com/gin-gonic/gin" in any of:
> test_server |
> /usr/local/go/src//go/src/test_server/vendor/github.com/gin-gonic/gin
> (from $GOROOT) test_server |
> /go/src/_/go/src/test_server/vendor/github.com/gin-gonic/gin (from
> $GOPATH)
它指的是controllers包。我正在使用github.com/kardianos/govendor来管理我的包依赖。你知道出了什么问题吗?
英文:
I'm writing a simple app in GO and I have this folder structure
The docker-compose.yml file content is:
version: '2'
services:
db:
image: rethinkdb:latest
ports:
- "38080:8080"
- "38015:28015"
- "39015:29015"
api:
image: golang:1.8-alpine
volumes:
- .:/go/src/test_server/
working_dir: /go/src/test_server
command: go run server.go
container_name: test_server
ports:
- "8085:8085"
links:
- db
tty: true
Everytime I run docker-compose up I receive this error message:
> test_server | controllers/users.go:4:3: cannot find package
> "/go/src/test_server/vendor/github.com/gin-gonic/gin" in any of:
> test_server |
> /usr/local/go/src//go/src/test_server/vendor/github.com/gin-gonic/gin
> (from $GOROOT) test_server |
> /go/src/_/go/src/test_server/vendor/github.com/gin-gonic/gin (from
> $GOPATH)
It's referring to the controllers package. I'm using github.com/kardianos/govendor to vendor my packages. Do you know what's going on?
答案1
得分: 4
经过多个小时的努力,我终于修复了它。
结果是我使用的 Docker Golang 版本不包含 git。我应该使用 golang:1.8。
我修改了我的 Dockerfile,现在它完美运行:
FROM golang:1.8
RUN go get github.com/gin-gonic/gin
WORKDIR /go/src/app
COPY . .
RUN go install -v
CMD ["app"]
英文:
After many hours I finally could fix it.
Resulted that I was using a docker golang version that it doesn't have git included. I should use golang:1.8
I modified my Dockerfile like this and now it works like a charm
FROM golang:1.8
RUN go get github.com/gin-gonic/gin
WORKDIR /go/src/app
COPY . .
RUN go install -v
CMD ["app"]
答案2
得分: 0
你需要告诉go在哪里找到这些包:
api:
...
environment:
- GOPATH=/go/src/test_server
或者使用已安装适当包的Dockerfile(推荐)。
英文:
You need to tell go where find the packages:
api:
...
environment:
- GOPATH=/go/src/test_server
Or have a Dockerfile with the proper packages installed (recommended)
答案3
得分: 0
我认为这是因为你的更新代码正在运行go install
,而不是你的旧代码运行的go run
。
你需要将额外的golang包安装到你的应用程序调用的供应商目录中。
英文:
I think it's because your updated code is running go install, not go run which your old code was running.
You needed to install the extra golang packages into the vendor directory that you are calling from your app.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论