Docker-Compose file has yaml.scanner.ScannerError
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
And I forgot :
after version
version '2'
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. :)
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.