compose.yml file, which looks like this:
version: \'2\'
services:
discovery-microservice:
build: discovery-microservice
context: /discov
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.