Docker-Compose:服务xxx取决于未定义的服务xxx

时间:2018-10-01 07:01:47

标签: linux docker docker-compose devops

我遇到此错误:

  

错误:服务'db'取决于未定义的服务'apache'。

为什么说apache未定义?我检查缩进。应该是正确的。

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

2 个答案:

答案 0 :(得分:3)

否,未定义。您已经用另一个services覆盖了。

您应该修复配置:

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

答案 1 :(得分:1)

@techraf是正确的。但是没有关键信息。切勿在撰写文件中写入2个服务。