0

I want to run the Spring Boot enabled and spring cloud config project to deploy to Docker. The below is the docker-compose.yml file. But I'm getting the following error while running the file.

Error:

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

Below is my docker-compose.yml file:

    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

I have tried multiple indentations changes for docker-compose.yml file.

The mentioned services are already built by maven. Need help in running the docker composer for the application.

1 Answer 1

0

There are multiple errors.

  1. Make sure that you only use spaces for indentation (instead of tabs). If you are interested why tabs don't work within yaml files have a look at A YAML file cannot contain tabs as indentation
  2. put your ports into strings (e.g. - "8060:8060"instead of - 8060:8060)
  3. I think you are misusing environment variables. They should/must look like e.g.:

environment: - JAVA_OPTS - EUREKA_SERVER=http://discovery:8761/eureka - ANOTHER_ENV_VARIABLE=/config-data

Have a look at the docs for details: https://docs.docker.com/compose/environment-variables/

After fixing your docker-compose.yml you can validate your file by running docker-compose config inside of the directory where your docker-compose.yml is located.

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you for the reply. I have done the changes as you mentioned above. But I am still getting the error for below two lines -DEUREKA_SERVER=http://discovery:8761/eureka/ -Dspring.cloud.config.server.native.searchLocations="/config-data" Error is: ` ERROR: yaml.scanner.ScannerError: while scanning a simple key in "./docker-compose.yml", line 13, column 6 could not find expected ':' in "./docker-compose.yml", line 14, column 6 '
Yes, this is what I mentioned under 3.. You can't use environment variables like that: -DEUREKA_SERVER=http://discovery:8761/eureka/. It has to be - EUREKA_SERVER=http://discovery:8761/eureka. Have a look at the syntax. There needs to be a space between the - and the variable name. Please be aware of the fact that you are defining environment variables here. It seems like you are confounding environment variables and java system properties (-D) here.
Once again thank you. The last error I am getting is : ERROR: 'The Compose file './docker-compose.yml' is invalid because: Unsupported config option for services.discovery: 'config' ' . Please let me know how to configure the config option.
Please have another look at your indentations. config is not an option but the name of a service (like discovery, organization-service, ...). It has to be on the same level of indentation as the other services. As the error says docker interprets config as an option named config (which does not exist). But instead config is the name of a service.
Thank you very much. I am really thankful to you as yours response is quick and its fixes the issues !!! While Running the 'docker-compose up -d' I am getting error like ERROR: Get pl.app.service/v1/_ping: dial tcp: lookup pl.piomin.service on 10.168.57.53:53: no such host Please help me on this. Thank you in advance !! :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.