go-yaml load error in scanner (while scanning an alias) ... did not find expected
alphabetic or numeric character means a value in your Compose file starts with an
unquoted *. YAML reads * as the start of an alias name and finds no
name after it. Put the value in quotes: "*".
The same message with (while scanning an anchor) comes from an unquoted
&. Both characters have a meaning in YAML at the start of a value, and
quoting turns them back into plain text.
The error
PS> docker compose -f compose.yaml config
go-yaml load error in scanner (while scanning an alias) at L7.C22-C23: did not find expected alphabetic or numeric character
The file, with a wildcard value for an environment variable:
name: fix10-cy-p8
services:
web:
image: alpine
command: ["sleep", "1"]
environment:
ALLOWED_HOSTS: *
Why it happens
YAML lets you name a block with an anchor, &name, and reuse it elsewhere
with an alias, *name. So when a value begins with *, the scanner reads an
alias and expects a name made of letters or digits right after it. Here the line ends at
column 23, so there is no name, and the scanner stops before Compose reads any service.
An & at the start of a value fails the same way, as an anchor without a
name:
PS> docker compose -f compose.amp.yaml config
go-yaml load error in scanner (while scanning an anchor) at L7.C18-C19: did not find expected alphabetic or numeric character
The fix
name: fix10-cy-p8
services:
web:
image: alpine
command: ["sleep", "1"]
environment:
ALLOWED_HOSTS: "*"
PS> docker compose -f compose.fixed.yaml config
...
environment:
ALLOWED_HOSTS: '*'
...
In quotes the value is a one-character string, and config prints it back as
'*', still quoted, because its output is YAML too. The quotes belong to the
file, not to the value. A test service with one variable in double quotes and one in
single quotes echoed both inside the container:
command: ["sh", "-c", "echo \"[$$ALLOWED_HOSTS] [$$SINGLE]\""]
environment:
ALLOWED_HOSTS: "*"
SINGLE: '*'
PS> docker compose -f compose.run.yaml up
...
web-1 | [*] [*]
...
Both arrived as a plain *, so either kind of quote does the job.
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 ALLOWED_HOSTS: * under
environment gave the message above on docker compose -f compose.yaml
config with exit code 1, and a second file with SEPARATOR: & gave
the anchor variant; with "*" the same command printed the model with exit code
0, and docker compose up on the test service with the cached
alpine image printed the two values. The project name fix10-cy-p8 is the test's own.
Frequently asked
- What does did not find expected alphabetic or numeric character mean in docker compose?
- A value starts with an unquoted * or &. YAML reads them as an alias or an anchor and expects a name after them. Quote the value.
- How do I set an environment variable to * in docker compose?
- Write it in quotes, ALLOWED_HOSTS: "*". In the test config printed it back as '*' and the file was accepted.
- What is the difference between scanning an alias and scanning an anchor?
- The alias variant came from a value starting with *, the anchor variant from a value starting with &. The fix is the same: quote the value.
More decoded errors in the Fixes category. An alias that does have a name but points to no anchor gives unknown anchor referenced.