A config file that looks perfect and still fails usually has an invisible culprit: a tab where spaces belong, or a Windows line ending.
cat -A prints a file with the invisible parts spelled out. The man page says it is equivalent to -vET: -E displays $ or ^M$ at the end of each line, -T shows tabs as ^I, and -v uses ^ and M- notation for other non-printing characters.
cat -A docker-compose.yml
Say the output looks like this:
services:^M$
^Iweb:$
image: nginx $
The first line ends in ^M$, so it has a carriage return from a Windows line ending. The second line starts with ^I, a tab, which YAML does not accept for indentation. On the last line the spaces before the $ are trailing whitespace that you could not see before.
Seeing the problem is half of it. To fix the line endings you still need something like dos2unix, or sed -i 's/\r$//' file. Make a copy first, since sed -i edits the file in place.
This is the GNU cat option. The cat on macOS may not know -A, and cat -et gives similar output there. For a huge file, pipe it through less or head, because every character gets a notation and the output grows.
Further reading: cat(1) manual page