go-yaml load error in composer at L7.C9: unknown anchor 'commn' referenced
means an alias such as *commn points to an anchor that does not exist above it
in the file. In the test it was a typo of *common. Make the alias match the
anchor name exactly, and define the anchor before its first use.
The message quotes the name it could not find, so compare it letter by letter with the
&name on your x- block. Line 7, column 9 is the alias itself,
the first character after <<: on that line.
The error
PS> docker compose -f compose.yaml config
go-yaml load error in composer at L7.C9: unknown anchor 'commn' referenced
The file, with a shared block reused by two services:
name: fix10-cy-p9
x-common: &common
image: alpine
command: ["sleep", "1"]
services:
web:
<<: *commn
worker:
<<: *common
Why it happens
&common gives the x-common block a name, and
*common pastes that block in where it appears; <<: merges
its keys into the service. An alias is looked up by its exact name, so
*commn finds nothing and the file stops loading at that line.
The name can also be right and the order wrong. The same file with the
x-common block moved below the services gave the error for the correct name:
PS> docker compose -f compose.order.yaml config
go-yaml load error in composer at L4.C9: unknown anchor 'common' referenced
So the anchor has to appear earlier in the file than the alias that uses it; moving the block back to the top fixed this second file too.
The fix
name: fix10-cy-p9
x-common: &common
image: alpine
command: ["sleep", "1"]
services:
web:
<<: *common
worker:
<<: *common
PS> docker compose -f compose.fixed.yaml config
name: fix10-cy-p9
services:
web:
command:
- sleep
- "1"
image: alpine
networks:
default: null
worker:
command:
- sleep
- "1"
image: alpine
networks:
default: null
...
With the alias spelled like the anchor, both services receive the image and the command
from the shared block, as config shows. The resolved output also prints the
x-common block itself at the end, after the networks (cut above).
How it was reproduced
Docker Desktop on Windows 11, Docker Compose v5.7.0, engine 29.9.3, Windows PowerShell
5.1. A two-service compose.yaml sharing an x-common block, with
one alias misspelled as *commn, gave the message above on docker compose
-f compose.yaml config with exit code 1; a second file with the block below the
services gave the 'common' variant; the corrected file printed the model with
exit code 0. No container was started. The project name fix10-cy-p9 is the
test's own.
Frequently asked
- What does unknown anchor referenced mean in docker compose?
- An alias such as *commn names an anchor that is not defined earlier in the file. In the test it was a typo of the anchor name common.
- Does the order of anchors matter in a compose file?
- Yes. With the x-common block moved below the services that used it, the correct name *common gave unknown anchor 'common' referenced.
- How do I share settings between compose services?
- Define a top-level x- block with an anchor, x-common: &common, and merge it into each service with <<: *common, as in the fixed file of this post.
More decoded errors in the Fixes category. A
* with no name after it at all gives
did
not find expected alphabetic or numeric character.