Docker Compose找不到本地软件包

编程入门 行业动态 更新时间:2024-10-28 21:18:18
本文介绍了Docker Compose找不到本地软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我在GOlang中创建了REST api和一个grpc服务,现在我想在docker compose中进行编写。 我的docker-compose看起来像这样:

So I created REST api and one grpc service in GOlang and now I want to compose it in docker compose. My docker-compose looks like this:

version: '3' services: db: image: postgres environment: POSTGRES_DB: db_1 POSTGRES_USER: postgres POSTGRES_PASSWORD: tajna PGDATA: /tmp volumes: - ./db/sql/user/1_create.sql:/docker-entrypoint-initdb.d/1-create_user.sql - ./db/sql/item/2_create.sql:/docker-entrypoint-initdb.d/2-create_item.sql ports: - 5432:5432 networks: apinetwork: service: build: ./item-service command: ["go", "run", "."] volumes: - .:/go/src/github/ajdinahmetovic/item-service ports: - "4040:4040" depends_on: - db links: - db networks: apinetwork: rest: image: go-rest build: context: ./go-rest dockerfile: Dockerfile command: ["go", "run", "main.go"] volumes: - .:/go/src/github/ajdinahmetovic/go-rest ports: - "3000:3000" depends_on: - service networks: apinetwork: networks: apinetwork: driver: bridge

在我运行docker-compose之后,我收到错误消息,说里面的本地软件包

After I run docker-compose up I get error that local packages that are inside of go-rest and item-service could not be found.

service_1 | item.go:7:2: no Go files in /go/src/github/ajdinahmetovic/item-service/db service_1 | main.go:8:2: cannot find package "github/ajdinahmetovic/item-service/logger" in any of: service_1 | /usr/local/go/src/github/ajdinahmetovic/item-service/logger (from $GOROOT) service_1 | /go/src/github/ajdinahmetovic/item-service/logger (from $GOPATH) service_1 | item.go:8:2: cannot find package "github/ajdinahmetovic/item-service/proto/v1" in any of: service_1 | /usr/local/go/src/github/ajdinahmetovic/item-service/proto/v1 (from $GOROOT) service_1 | /go/src/github/ajdinahmetovic/item-service/proto/v1 (from $GOPATH) ajdinahmetovic_service_1 exited with code 1 rest_1 | /go/src/github/ajdinahmetovic/go-rest/routes/item/post.go:9:2: no Go files in /go/src/github/ajdinahmetovic/go-rest/db rest_1 | /go/src/github/ajdinahmetovic/go-rest/routes/refreshToken.go:9:2: cannot find package "github/ajdinahmetovic/go-rest/httputil" in any of: rest_1 | /usr/local/go/src/github/ajdinahmetovic/go-rest/httputil (from $GOROOT) rest_1 | /go/src/github/ajdinahmetovic/go-rest/httputil (from $GOPATH) ajdinahmetovic_rest_1 exited with code 1

$ b退出 $ b

但是,当我将docker compose文件移动到go-rest文件夹时,rest app成功运行,但是我的项目服务失败。如我所见,问题出在我开发应用程序的道路上。

However when I move docker compose file to go-rest folder, rest app succcessfuly runs but my item service fails. As i see problem is in my path to go apps.

推荐答案

几个小时后,我终于意识到问题出在哪里。 我用于项目服务和休息的音量路径错误。 因为我的docker-compose文件与项目item-service和go-rest项目的文件夹处于同一级别

After couple of hours I finally realized what the problem was. My volume path for item-service and go-rest were wrong. Becuse my docker-compose file is on the same level with folders of projects item-service and go-rest

-go-rest -Project files -item-service -Project files -docker-compose.yaml

,我的音量路径为

volumes: - .:/go/src/github/ajdinahmetovic/go-rest volumes: - .:/go/src/github/ajdinahmetovic/item-service

他们无法访问我的项目文件夹,因此需要将其更改为

They were not able to acces my project folder so they need to be changed to

volumes: - .:/go-rest volumes: - .:/item-service

更多推荐

Docker Compose找不到本地软件包

本文发布于:2023-07-04 03:32:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1016821.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   软件包   Docker   Compose

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!