On https://docs.docker.com/compose/compose-file/#networks networks are specified as:
networks:
- some-network
- other-network
Using docker-compose version 1.6.2, build 4d72027
and a version 2 file I get this error:
ERROR: In file './docker-compose.yml', network must be a mapping, not an array.
The correct syntax seems to be:
networks:
some-network:
other-network:
It's confusing, but there are two different networks
keys:
networks
at the top-level of the Compose file. This must always be a mapping.networks
inside a service definition. This can be a mapping or an array.Here's an example:
version: "2"
services:
web:
build: .
networks:
- foo
networks:
foo:
yeah, looks like you are right. thanks anyway.
Thanks Hendrik-H you solved my issue. They really should document that better. I had multiple networks defined with an IP address and it kept giving me the error.
Original definition
networks:
- rcon01:
ipv4_address: 172.40.1.2
- rnet50
Gave:
ERROR: The Compose file './docker-compose.yaml' is invalid because:
services.r3.networks contains {"rcon01": {"ipv4_address": "172.40.1.2"}}, which is an invalid type, it should be a string
New definition works:
networks:
rcon01:
ipv4_address: 172.40.1.2
rnet50:
Most helpful comment
It's confusing, but there are two different
networks
keys:networks
at the top-level of the Compose file. This must always be a mapping.networks
inside a service definition. This can be a mapping or an array.Here's an example: