Docker-Compose file has yaml.scanner.ScannerError

后端 未结 17 2099
情话喂你
情话喂你 2021-02-01 12:04

compose.yml file, which looks like this:

version: \'2\'
services:
  discovery-microservice:
    build: discovery-microservice
      context: /discov         


        
相关标签:
17条回答
  • 2021-02-01 12:45

    I wanted a volume mapped to a specific path on the external (host) server. I tried putting that under the top-level volumes entry in docker-compose.yml. After looking at the docker-compose file docs, I realized that that type of volume does not go there. Instead, it goes only under the volumes entry within the container definition. E.g.:

    version: "3.7"
    services:
      web:
        image: my_custom_web_image
        build: ./app
        volumes:
          - ./app/subdir:/usr/src/app/subdir
    
    0 讨论(0)
  • 2021-02-01 12:47

    So, there is another reason! When you try to install r=Redash using the setup.sh from the Github, the script automatically gets the latest version of Redash and put it in docker-compose.yml. The base yml file doesn't have single-quotations (') around version name! As a result, you get an error that says:

    ERROR: yaml.scanner.ScannerError: mapping values are not allowed here in "./docker-compose.yml", line 3, column 23 You just add single-quotation around the Redash version:

    version: "2"
    x-redash-service: &redash-service
      image: 'redash/redash:8.0.0.b32245'

    0 讨论(0)
  • 2021-02-01 12:50

    Also make sure you have context and dockerfile at the same identation. I made a mistake and was stuck for hours.

    My error was

    ERROR: yaml.scanner.ScannerError: mapping values are not allowed here in "./docker-compose.yml", line 6, column 19

    Wrong:

    version : '3'
    services:
      test:
        build:
          context: ./test
            dockerfile: Dockerfile.test
        image: kpod/test:2020
    

    Right:

    version : '3'
    services:
      test:
        build:
          context: ./test
          dockerfile: Dockerfile.test
        image: kpod/test:2020
    
    0 讨论(0)
  • 2021-02-01 12:52

    Ok, I wasted around 3 hours to debug a similar issue.

    If you guys ever get the below error

    ERROR: yaml.scanner.ScannerError: mapping values are not allowed here
    in ".\docker-compose.yml", line 2, column 9
    

    It's because a space is needed between

    version:'3' <-- this is wrong

    version: '3' <-- this is correct.

    Also, if you are using eclipse, do yourself a favor and install the YEdit YAML editor plugin

    0 讨论(0)
  • 2021-02-01 12:52

    I encountered a similar issue today, a syntax error in the docker-compose.yml file that caused the same error.

    version: '2'
    services:
    // Add your services here
      discovery-microservice:
        build: discovery-microservice
          context: ./discovery-microservice/target/docker
          dockerfile: Dockerfile
      ports:
       - "8761:8761"
    

    Removing this line // Add your services here fixed my issue

    version: '2'
    services:
      discovery-microservice:
        build:
          context: ./discovery-microservice/target/docker
          dockerfile: Dockerfile
        ports:
         - "8761:8761"
    

    I hope this helps someone with a similar issue.

    0 讨论(0)
  • 2021-02-01 12:53

    If you are using vs code do yourself a favor and install YAML extension by "RedHat".

    0 讨论(0)
提交回复
热议问题