无效的顶级属性“ app01”。此Compose文件的有效顶级部分为:版本,服务,网络,卷和扩展名

时间:2019-07-19 04:59:31

标签: docker docker-compose

执行此命令时出现错误:

“ docker-compose build && docker-compose up”

我试图将docker-compose文件中的版本号更改为3.3,但这也不起作用。

我的docker-compose文件如下所示”

version: '2.1'
control:
  build: ./env
  hostname: control
  links:
    - lb01
    - app01
    - app02
    - db01
  ports:
    - "2200:22"
  volumes:
    - ./:/work
lb01:
  build: ./env
  hostname: lb01
  links:
    - app01
    - app02
  ports:
    - "2201:22"
    - "8001:80"
app01:
  build: ./env
  hostname: app01
  links:
    - db01
  ports:
    - "2211:22"
    - "8081:80"
app02:
  build: ./env
  hostname: app02
  links:
    - db01
  ports:
    - "2212:22"
    - "8082:80"
db01:
  build: ./env
  hostname: db01
  ports:
    - "2222:22"
    - "3306:3306"

每当我运行上述命令时,我都会收到此错误:

ERROR: The Compose file '.\docker-compose.yml' is invalid because:
Invalid top-level property "app01". Valid top-level sections for this Compose file are version, services, networks, volumes, and extensions starting with "x-".

You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version (e.g "2.2" or "3.3") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/

1 个答案:

答案 0 :(得分:0)

请参阅第2行:

version: '2.1'
services:
  control:
    build: ./env
    hostname: control
    links:
      - lb01
      - app01
      - app02
      - db01
    ports:
      - "2200:22"
    volumes:
      - ./:/work
  lb01:
    build: ./env
    hostname: lb01
    links:
      - app01
      - app02
    ports:
      - "2201:22"
      - "8001:80"
  app01:
    build: ./env
    hostname: app01
    links:
      - db01
    ports:
      - "2211:22"
      - "8081:80"
  app02:
    build: ./env
    hostname: app02
    links:
      - db01
    ports:
      - "2212:22"
      - "8082:80"
  db01:
    build: ./env
    hostname: db01
    ports:
      - "2222:22"
      - "3306:3306"