WhoAmI
WhoAmI

Reputation: 1133

Docker-Compose: Service xxx depends on service xxx which is undefined

I'm having this error:

ERROR: Service 'db' depends on service 'apache' which is undefined.

Why is it saying that apache is undefined? I check the indentation. Should be the right one.

version: '3.5'

services:
  apache:
    build: ./Docker
    image: apache:latest
    ports:
     - "80:80"
    restart: always
networks:
       default:
         name: frontend-network

services:
  db:
    image: mariadb:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
    depends_on:
    - "apache"
  adminer:
    image: adminer
    restart: always
    ports:
    - "8080:8080"
    depends_on:
    - "db"
networks:
      default:
        name: frontend-network

Upvotes: 9

Views: 34560

Answers (2)

Igor
Igor

Reputation: 1121

Just check for probably another errors in docker-compose.yml file, its not only about service name, for example i got this error because there was unused profiles key. Check carefully everything.

Upvotes: 1

techraf
techraf

Reputation: 68489

No, it's not defined. You have overwritten one services with the other one.

You should fix the configuration:

version: '3.5'

services:
  apache:
    build: ./Docker
    image: apache:latest
    ports:
     - "80:80"
    restart: always
  db:
    image: mariadb:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
    depends_on:
    - "apache"
  adminer:
    image: adminer
    restart: always
    ports:
    - "8080:8080"
    depends_on:
    - "db"

networks:
      default:
        name: frontend-network

Upvotes: 12

Related Questions