go-yaml load error in scanner at L4.C24: mapping values are not allowed in this context means the YAML scanner met a second key: on a line that already holds a value. Two keys share one line in your Compose file. Put the second key on its own line, at the same indentation as the first.

The position after at is line and column: line 4, column 24 is the colon of the key that should have started a new line. Go to that colon and press Enter in front of the key.

The error

PS> docker compose -f compose.yaml config
go-yaml load error in scanner at L4.C24: mapping values are not allowed in this context

The file, where ports: ended up on the image line:

name: fix10-cy-p1
services:
  web:
    image: alpine ports:
      - "127.0.0.1:15900:80"

Why it happens

In YAML a plain value runs to the end of its line. After image: the scanner reads alpine ports as the start of one string value. Then it meets : , a colon followed by a space, which in YAML marks a key. A key cannot sit in the middle of a value, so the scanner stops at that colon, column 24, before Compose sees any service at all.

A lost line break is the way this file got there: two lines joined by a stray Delete key, or a snippet pasted onto the end of an existing line. Because the scanner fails first, the message names neither the service nor the key; the line and column are the only pointer you get, so read them before anything else.

The fix

name: fix10-cy-p1
services:
  web:
    image: alpine
    ports:
      - "127.0.0.1:15900:80"
PS> docker compose -f compose.fixed.yaml config
name: fix10-cy-p1
services:
  web:
    image: alpine
    networks:
      default: null
    ports:
      - mode: ingress
        host_ip: 127.0.0.1
        target: 80
        published: "15900"
        protocol: tcp
...

With ports: back on its own line, four spaces in like image, the file parses and config prints the resolved model: the port list is expanded into its long form, which shows Compose read the mapping as intended (the output is cut after the service). If a value really must contain a colon followed by a space, put it in quotes, so the scanner reads it as one string.

How it was reproduced

Docker Desktop on Windows 11, Docker Compose v5.7.0, engine 29.9.3, Windows PowerShell 5.1. A one-service compose.yaml with ports: appended to the image line gave the message above on docker compose -f compose.yaml config with exit code 1; the same file with the line break restored printed the model with exit code 0. No container was started. The project name fix10-cy-p1 is the test's own.

Frequently asked

What does mapping values are not allowed in this context mean in docker compose?
The YAML scanner found a key, a word followed by a colon and a space, in the middle of a value. In the test it was a second key written on the same line as the first.
How do I find the line in a go-yaml load error?
Read the position after at. L4.C24 is line 4, column 24, and in this case it pointed at the colon of the key that needed its own line.
Can a compose value contain a colon?
Yes. In the test, image: alpine:latest and an unquoted - 127.0.0.1:15900:80 both parsed, because no colon in them is followed by a space. Quote any value that needs a colon and a space.

More decoded errors in the Fixes category. A key that is on its own line but indented wrongly gives a different message, covered in go-yaml load error in parser ... did not find expected key.