go-yaml load error in scanner (while scanning a simple key) ... could not find expected ':' means a line inside a mapping holds a bare word with no colon after it. In the test it was an environment variable written as LANG under a mapping of KEY: value pairs. Give the line a colon and a value.

The range L8.C7-L9.C1 starts at the word without a colon (line 8, column 7) and ends where the scanner gave up looking for one, the start of the next line. The broken line is the first one in the range.

The error

PS> docker compose -f compose.yaml config
go-yaml load error in scanner (while scanning a simple key) at L8.C7-L9.C1: could not find expected ':'

The file:

name: fix10-cy-p2
services:
  web:
    image: alpine
    command: sleep 1
    environment:
      GREETING: hello
      LANG

Why it happens

environment opens a mapping with GREETING: hello, so every line at that indentation must be another key: value pair. The scanner takes LANG as the start of a new key and reaches the next line, here the end of the file, without finding the colon a key needs. It stops there, before Compose reads a single service.

Compose also accepts environment as a list of - KEY=value lines, and a list item may be a bare - LANG. Mixing the two styles is one way this line appears: a name copied from a list-style file into a mapping-style one, without its dash.

The fix

name: fix10-cy-p2
services:
  web:
    image: alpine
    command: sleep 1
    environment:
      GREETING: hello
      LANG: C.UTF-8
PS> docker compose -f compose.fixed.yaml config
name: fix10-cy-p2
services:
  web:
    command:
      - sleep
      - "1"
    environment:
      GREETING: hello
      LANG: C.UTF-8
...

With a colon and a value on the line, the file parses and config shows both variables in the resolved model (the output is cut after them). The list style is the other way out: - GREETING=hello and a bare - LANG under environment also parsed in the test, and config showed the bare name as LANG: null. Whichever you pick, keep one style for the whole block.

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 whose environment mapping ended with a bare LANG gave the message above on docker compose -f compose.yaml config with exit code 1; with LANG: C.UTF-8 the same command printed the model with exit code 0. No container was started. The project name fix10-cy-p2 is the test's own.

Frequently asked

What does could not find expected ':' mean in docker compose?
The YAML scanner found a line in a mapping that starts like a key but has no colon. In the test it was a bare LANG under an environment block of KEY: value lines.
Which line does L8.C7-L9.C1 point to?
The first position, line 8, column 7, is the word without a colon. The second is where the scanner stopped looking, the start of the next line.
Can I list an environment variable without a value in compose?
In the list style, a bare - LANG item parsed in the test and config showed it as LANG: null. In the mapping style the line needs a colon, so write LANG: with a value.

More decoded errors in the Fixes category. A list item that lost its dash printed this same message; that case is shown in did not find expected '-' indicator. Two keys on one line give a different scanner message, covered in mapping values are not allowed in this context.