mapping values are not allowed here
Fixes the docker-compose error `mapping values are not allowed here`. It explains the verified fix from a real resolved case, when it applies, and what to check first. Not for unrelated docker-compose failures or different error text.
Fix mapping values are not allowed here (docker-compose)
TL;DR
Your compose file has a tab character (or bad indentation) where YAML expects spaces. Search the file for tabs, replace them with spaces, and re-run. docker compose config tells you instantly whether the file parses now.
The error, verbatim:
mapping values are not allowed hereSteps
- Find the tab characters in the compose file:
grep -Pn " " docker-compose.ymlSuccess check: cat -A shows ^I wherever a tab hides; grep finds the lines.
- Replace every tab with spaces (2 spaces per indent level is the compose convention):
grep -Pn " " docker-compose.ymlSuccess check: No output means no tabs remain.
- Validate the file parses cleanly:
docker compose configSuccess check: The parsed file prints with no errors.
When to use
You hit this exact error while using docker-compose. The trigger list below matches your situation.
When NOT to use
If the error text differs, or the failure is in a different tool (e.g. a Docker daemon error when you only need the compose fix), find the skill for that exact error instead.
Tool compatibility
docker-compose v1 and Compose v2. Any OS; common on Windows editors.
Variant phrasings
mapping values are not allowed here
yaml: mapping values are not allowed here
Root cause
YAML forbids tab characters for indentation. A tab (or a misaligned colon, like key value value split across a line break) makes the YAML parser read a mapping where it expected a scalar, and compose surfaces the parser error. It is always a whitespace problem in the compose file, never a compose bug.
Edge cases
- A stray tab anywhere in the file breaks parsing, not just near the reported line.
- Copy-pasting from web pages can introduce non-breaking spaces that look like spaces but are not.
- After fixing, docker compose config is the fastest way to confirm the file parses.
Where this came from
Resolved from the public discussion at https://stackoverflow.com/questions/39077526 (so:39077526).
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.