go-yaml load error in scanner (while scanning for the next token) at L4.C1: found character that cannot start any token
— in this test the character was a tab: line 4 of the Compose file was indented with a tab
instead of spaces, and the YAML parser stopped there. Replace the tab with
spaces and the file loads.
The message gives the position as L4.C1: line 4, column 1. Go to that line,
search the file for tab characters to be sure there is no second one, and indent with
spaces only.
The error
PS> docker compose up -d
go-yaml load error in scanner (while scanning for the next token) at L4.C1: found character that cannot start any token
The command exited with code 1, and docker compose config printed the same
line with the same exit code. On screen the file looked like this, with the tab at the
start of line 4 shown here as it was saved:
name: fix9-cmp-c4
services:
web:
image: alpine
command: ["sleep", "300"]
Why it happens
YAML uses indentation for structure, and the file's structure here depends on
image: being indented under web:. The YAML parser stopped at the
tab, at column 1 because the tab is the first character of the line, and Compose created
no network and no container. The message comes from the parser, not from the Compose
schema, so it says nothing about services or keys: only a line and a column.
In an editor a tab and a run of spaces can look the same, which is how a file can look fine and still fail. The position in the message is the one to trust, not the look of the file.
The fix
To find the tabs, search for them. In PowerShell, Select-String with the
regular expression \t printed the file name, the line number and the line:
PS> Select-String -Path .\compose.yaml -Pattern '\t'
compose.yaml:4: image: alpine
After the tab was replaced with four spaces, the same search printed nothing and the project started:
name: fix9-cmp-c4
services:
web:
image: alpine
command: ["sleep", "300"]
PS> docker compose up -d
Network fix9-cmp-c4_default Creating
...
Container fix9-cmp-c4-web-1 Started
The indent has to match its siblings: image: and command: sit at
the same depth under web:. Setting your editor to insert spaces for YAML files
keeps the next tab out.
How it was reproduced
A one-service alpine file whose fourth line began with a tab character,
written from PowerShell, loaded with docker compose up -d and
docker compose config from Windows PowerShell 5.1 on Docker Engine 29.9.3 and
Docker Compose v5.7.0 (Docker Desktop on Windows 11). The project name carries this test's
fix9-cmp- prefix and was removed with docker compose down -v.
Frequently asked
- What does 'found character that cannot start any token' mean in docker compose?
- In this test it meant a tab character at the start of a line in the Compose file. Replacing it with spaces fixed the file; the message gives the line and column, here L4.C1.
- How do I find tabs in a docker-compose.yml file?
- In PowerShell run Select-String -Path .\compose.yaml -Pattern '\t'. It printed the file name, line number and line of each match, and nothing once the tab was gone.
- Can I indent docker-compose.yml with tabs?
- No. The file with one tab of indentation was rejected by both docker compose up and docker compose config. Indent with spaces, matching the depth of the sibling keys.
More decoded errors in the Fixes category. For another YAML load error from the same parser, see Docker Compose: go-yaml load error, did not find expected key.