如何运行此Docker Compose文件

时间:2019-03-27 15:45:44

标签: docker-compose

我的docker-compose文件中有一个错误,但无法理解是什么错误。 我从Kubernetes教程中获得了它。 错误是

yaml.parser.ParserError: while parsing a block mapping
  in "./docker-compose.yml", line 1, column 1
expected <block end>, but found '<block mapping start>'
  in "./docker-compose.yml", line 2, column 3

文件是:

version: "2"
  services:
    redis-master:
      image: k8s.gcr.io/redis:e2e
        ports:
          - "6379"

      redis-slave:
        image: gcr.io/google_samples/gb-redisslave:v1
        ports:
          - "6379"
        environment:
          - GET_HOSTS_FROM=dns

      frontend:
        image: gcr.io/google-samples/gb-frontend:v4
        ports:
          - "80:80"
        environment:
          - GET_HOSTS_FROM=dns
        labels:
          kompose.service.type: LoadBalancer

1 个答案:

答案 0 :(得分:1)

我能发现的唯一问题是撰写文件的缩进不正确。

尝试使用此版本的撰写文件:

version: "2"

services:
  redis-master:
    image: k8s.gcr.io/redis:e2e
    ports:
      - "6379"
  redis-slave:
    image: gcr.io/google_samples/gb-redisslave:v1
    ports:
      - "6379"
    environment:
      - GET_HOSTS_FROM=dns
  frontend:
    image: gcr.io/google-samples/gb-frontend:v4
    ports:
      - "80:80"
    environment:
      - GET_HOSTS_FROM=dns
    labels:
      kompose.service.type: LoadBalancer

有关YAML结构的更多详细信息,this是一个很好的起点。