服务”app”依赖于未定义的服务”db”:无效的Compose项目。

huangapple go评论182阅读模式
英文:

service "app" depends on undefined service db: invalid compose project

问题

我在Gin框架中构建了一个Go服务器,现在我想将其部署到GCP。我正在尝试在GCP Compute Engine的虚拟机上运行docker compose up -d命令。该命令在我的本地机器上成功运行,但在虚拟机终端中显示错误。
我在终端中收到的错误是:
service "app" depends on undefined service db: invalid compose project

我的docker-compose.yml代码如下:

  1. version: "3.7"
  2. services:
  3. database:
  4. container_name: mywealth-database
  5. image: postgres:12.8
  6. restart: always
  7. environment:
  8. - POSTGRES_USER=sharauq
  9. - POSTGRES_PASSWORD=sharauq
  10. - POSTGRES_DB=mywealth
  11. ports:
  12. - 5432:5432
  13. volumes:
  14. - db:/var/lib/postgresql/data
  15. app:
  16. container_name: app
  17. restart: always
  18. build: .
  19. ports:
  20. - "8080:8080"
  21. depends_on:
  22. - db
  23. volumes:
  24. db:

我的Dockerfile如下:

  1. # Start from the latest golang base image.
  2. FROM golang:latest
  3. # Add maintainer information
  4. LABEL maintainer="sharaukadr2001@gmail.com"
  5. # Set the current working directory inside an image.
  6. WORKDIR /app
  7. # Copy Go module dependency requirements file.
  8. COPY go.mod .
  9. # Copy Go Modules expected hashes file.
  10. COPY go.sum .
  11. # Download dependencies.
  12. RUN go mod download
  13. # Copy all sources.
  14. COPY . .
  15. # Build the application.
  16. RUN go build -o /mywealth
  17. # Delete source files.
  18. RUN find . -name "*.go" -type f -delete
  19. # Run the application.
  20. CMD ["/mywealth"]
英文:

I build a Go server in Gin framework and now I want to deploy it to GCP. I am trying to run docker compose up -d on VM in GCP Compute Engine. The command successfully runs in my local machine but shows error in VM terminal
The error I am getting in terminal is:
service "app" depends on undefined service db: invalid compose project

My docker-compose.yml code is:

  1. version: "3.7"
  2. services:
  3. database:
  4. container_name: mywealth-database
  5. image: postgres:12.8
  6. restart: always
  7. environment:
  8. - POSTGRES_USER=sharauq
  9. - POSTGRES_PASSWORD=sharauq
  10. - POSTGRES_DB=mywealth
  11. ports:
  12. - 5432:5432
  13. volumes:
  14. - db:/var/lib/postgresql/data
  15. app:
  16. container_name: app
  17. restart: always
  18. build: .
  19. ports:
  20. - "8080:8080"
  21. depends_on:
  22. - db
  23. volumes:
  24. db:

My Dockerfile is:

  1. # Start from the latest golang base image.
  2. FROM golang:latest
  3. # Add maintainer information
  4. LABEL maintainer="sharaukadr2001@gmail.com"
  5. # Set the current working directory inside an image.
  6. WORKDIR /app
  7. # Copy Go module dependency requirements file.
  8. COPY go.mod .
  9. # Copy Go Modules expected hashes file.
  10. COPY go.sum .
  11. # Download dependencies.
  12. RUN go mod download
  13. # Copy all sources.
  14. COPY . .
  15. # Build the application.
  16. RUN go build -o /mywealth
  17. # Delete source files.
  18. RUN find . -name "*.go" -type f -delete
  19. # Run the application.
  20. CMD ["/mywealth"]

答案1

得分: 2

你依赖其他服务,而不是卷。

你的数据库服务被称为 database,所以在 docker-compose.yml 文件中 app 服务定义的 depends_on 应该是 database,而不是 db

英文:

You 'depend' on other services. Not on volumes.

Your database service is called database, so the 'depends_on' in the app service definition in the docker-compose.yml file should be database. Not db.

huangapple
  • 本文由 发表于 2022年10月18日 00:55:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/74100665.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定