Docker Compose "ports must be a mapping" in CI
A service's ports: is a list of port mappings - short strings like "8080:80" or long-form mapping entries with target/published. Writing ports: as a single mapping (key/value object) instead of a list makes Compose reject the type.
What this error means
A docker compose up/config fails validating ports: - it should be a list of strings or long-form entries but was given a bare mapping.
docker
services.web.ports must be a list
# offending:
# ports:
# 8080: 80Common causes
ports written as a key/value mapping
Using 8080: 80 (a YAML mapping) instead of a list item "8080:80" is the wrong type.
Long-form entries not given as list items
Long-form target/published must each be a list item, not nested mapping keys under ports:.
How to fix it
Write ports as a list of strings
- Use list items with quoted
host:containerstrings.
docker-compose.yml
services:
web:
ports:
- "8080:80"
- "8443:443"Use long-form list items
- Express each mapping as a list item with target/published.
docker-compose.yml
services:
web:
ports:
- target: 80
published: 8080
protocol: tcpHow to prevent it
- Always write
ports:as a YAML list. - Quote short-form
host:containerstrings. - Validate with
docker compose config.
Related guides
Docker Compose "services.<name> must be a mapping" in CIFix Docker Compose "services.<name> must be a mapping" in CI - a service defined as a scalar or list instead…
Docker Compose "mapping values are not allowed" - Fix YAMLFix Docker Compose "yaml: mapping values are not allowed in this context" and "services must be a mapping" in…
Docker Compose "Bind for 0.0.0.0:PORT failed: port is already allocated" in CIFix Docker Compose "Bind for 0.0.0.0:PORT failed: port is already allocated" in CI - a leftover container, a…