dty98339 2019-09-24 13:25
浏览 298

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.com/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.com/ajdinahmetovic/go-rest
    ports:
      - "3000:3000"
    depends_on:
      - service
    networks: 
      apinetwork:
networks:
  apinetwork:
    driver: bridge

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

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.

  • 写回答

1条回答 默认 最新

  • dsxpt62448 2019-09-25 08:48
    关注

    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
    

    and my volume paths were

    volumes:
          - .:/go/src/github.com/ajdinahmetovic/go-rest
    volumes:
          - .:/go/src/github.com/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
    
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?