Docker-compose:运行启用了Spring Boot和Spring Cloud Config应用程序时出现的问题

时间:2019-04-09 08:10:12

标签: spring spring-boot docker docker-compose spring-cloud-config

我想运行启用了Spring Boot的Spring Cloud配置项目以部署到Docker。以下是docker-compose.yml文件。但是运行文件时出现以下错误。

错误:

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

以下是我的 docker-compose.yml 文件:

    version: '3'

    services:
          discovery:
            image: pl.app.service/discovery-service:0.0.1-SNAPSHOT
            ports:
              - 8061:8061
          config:
            image: pl.app.service/config-service:0.0.1-SNAPSHOT
            volumes:
              - ./config-data:/config-data
            environment:
               - JAVA_OPTS=
               -DEUREKA_SERVER=http://discovery:8761/eureka
               -Dspring.cloud.config.server.native.searchLocations=/config-data
             depends_on:
              - discovery
             ports:
              - 8088:8088

      proxy-service:
        image: pl.app.service/proxy-service:0.0.1-SNAPSHOT
        environment:
          - JAVA_OPTS=
            -DEUREKA_SERVER=http://discovery:8761/eureka
        depends_on:
          - discovery
          - config
        ports:
            -8060:8060

      employee-service:
        image: pl.app.service/employee-service:0.0.1-SNAPSHOT
        environment:
          - JAVA_OPTS=
            -DEUREKA_SERVER=http://discovery:8761/eureka
            -Dspring.profiles.active=dev
        restart: on-failure
        depends_on:
          - discovery
          - config
        ports:
            -8090:8090

      department-service:
          image: pl.app.service/organization-service:0.0.1-SNAPSHOT
        environment:
          - JAVA_OPTS=
            -DEUREKA_SERVER=http://discovery:8761/eureka
            -Dspring.profiles.active=dev
        restart: on-failure
        depends_on:
          - discovery
          - config
        ports:
            -8091:8091

       organization-service:
          image: pl.app.service/organization-service:0.0.1-SNAPSHOT
        environment:
          - JAVA_OPTS=
            -DEUREKA_SERVER=http://discovery:8761/eureka
            -Dspring.profiles.active=dev
        restart: on-failure
        depends_on:
          - discovery
          - config
        ports:
            -8092:8092

我尝试对docker-compose.yml文件进行多个缩进更改。

提到的服务已经由maven构建。在运行该应用程序的docker composer时需要帮助。

1 个答案:

答案 0 :(得分:0)

有多个错误。

  1. 请确保仅使用空格进行缩进(而不是制表符)。如果您有兴趣,为什么选项卡在yaml文件中不起作用,请查看A YAML file cannot contain tabs as indentation
  2. 将端口放入字符串(例如SELECT id, max(case when sortid=2 then StrValue end), max(case when sortid=3 then StrValue end), max(case when sortid=5 then StrValue end) FROM tablename GROUP BY id 而不是- "8060:8060"
  3. 我认为您正在滥用环境变量。它们应该/必须看起来像例如:

- 8060:8060

有关详细信息,请参阅文档:https://docs.docker.com/compose/environment-variables/

修复docker-compose.yml后,您可以通过在docker-compose.yml所在目录内运行environment: - JAVA_OPTS - EUREKA_SERVER=http://discovery:8761/eureka - ANOTHER_ENV_VARIABLE=/config-data来验证文件。