service "app" depends on undefined service db: invalid compose project
Asked Answered
M

1

6

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:

version: "3.7"

services:
  database:
    container_name: mywealth-database
    image: postgres:12.8
    restart: always
    environment:
      - POSTGRES_USER=sharauq
      - POSTGRES_PASSWORD=sharauq
      - POSTGRES_DB=mywealth
    ports:
      - 5432:5432
    volumes:
      - db:/var/lib/postgresql/data
  app:
        container_name: app
        restart: always
        build: .
        ports:
            - "8080:8080"
        depends_on: 
            - db

volumes:
  db:

My Dockerfile is:

# Start from the latest golang base image.
FROM golang:latest

# Add maintainer information
LABEL maintainer="[email protected]"

# Set the current working directory inside an image.
WORKDIR /app

# Copy Go module dependency requirements file.
COPY go.mod .

# Copy Go Modules expected hashes file.
COPY go.sum .

# Download dependencies.
RUN go mod download

# Copy all sources.
COPY . .

# Build the application.
RUN go build -o /mywealth

# Delete source files.
RUN find . -name "*.go" -type f -delete

# Run the application.
CMD ["/mywealth"]
Municipality answered 17/10, 2022 at 16:55 Comment(0)
P
6

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.

Prendergast answered 17/10, 2022 at 17:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.