In file docker-composeyml service 'environment' must be a mapping not an array¶
In a docker-compose.yml file, the environment section is used to define environment variables for a service. These environment variables are essentially key-value pairs, where each variable has a name (key) and a value associated with it.
A mapping, in the context of YAML (the format used for Docker Compose files), is a way to represent a set of key-value pairs. In YAML, a mapping is structured like this:
key1: value1 key2: value2 key3: value3
An array, on the other hand, is a list of values without associated keys. In YAML, an array is represented with a hyphen followed by a space:
- value1 - value2 - value3
Now, when Docker Compose is expecting the environment section to be formatted as a mapping, it means that it's expecting something like:
environment: key1: value1 key2: value2 key3: value3
However, if the environment section is mistakenly formatted as an array like this:
environment: - key1=value1 - key2=value2 - key3=value3
Docker Compose will throw an error because it's expecting key-value pairs (mapping) and not a list of values (array).
So, when you encounter the error message that says "The environment section should be formatted as a mapping, not an array," it means that Docker Compose expects the environment section to be structured using key-value pairs, not a list of values.
I hope this explanation clarifies why the correct formatting of the environment section is important in a docker-compose.yml file.
Updated by Gareth Eaton almost 2 years ago · 1 revisions