Docker-Compose file has yaml.scanner.ScannerError

匿名 (未验证) 提交于 2019-12-03 01:33:01

问题:

compose.yml file, which looks like this:

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

While I am executing it I get the following error:

yaml.scanner.ScannerError: mapping values are not allowed here in "C:\...\docker-compose.yml", line 5, column 14

From what I see, nothing is wrong with the format, e.g. whitespaces missing. My overall goal is to specify a development mode docker-compose file, pointing it to the target directories from the different modules.
What am I doing wrong here?

回答1:

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

Its because you need 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 YEdit YAML editor plugin



回答2:

And I forgot : after version

version '2'


回答3:

Literally found the solution seconds later. You have to remove the "discovery-microservice" after "build":

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

Also you can use "./" in context for relative paths. :)



回答4:

What is wrong is that here:

    build: discovery-microservice

you start a mapping which has a key build indented by four spaces. The value for that key is a scalar that starts with discovery-microservice and possible continues to the next line, depending on whether that has a key: value pair at the same indentation level or not

What is not allowed inside such a multiline scalar is that you have an unquoted : and have that at a different indentation level. Which is exactly what you do have.

The parser seeing context indented at a different level than build assumes you are writing a scalar string discovery-microservice context which cannot be followed on the same line (as context) by a colon.

Apart from removing discovery-microservice after build as you did in your answer, what would also make this valid YAML (but with a different meaning, probably non-sense for docker compose) are:

services:   discovery-microservice:     build: "discovery-microservice       context: /discovery-microservice/target/docker"

and

services:   discovery-microservice:     build: discovery-microservice     context: /discovery-microservice/target/docker"

For docker-compose version 2 files, the build key expects a mapping (and not a scalar as in the "solutions" above), making your answer the correct way to solve this.



回答5:

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.



回答6:

Hi further update to the given answer .... It's not specifically about the version: '2.0' line The statement

ERROR: yaml.scanner.ScannerError: mapping values are not allowed here

means there's a formatting error of some sort.

I got it and it was because I was missing a tab in my docker-compose file

version: '3.0' services:   mysql:   image: ...

instead of

version: '3.0' services:   mysql:     image: ...

Note the lack of an indenting tab on the image line



回答7:

Another possible culprit can be stray tabs at the end of the file, which I learned today.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!