compose-file network documentation seems to be wrong

Created on 30 Mar 2016  ·  3Comments  ·  Source: docker/compose

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:
areconfig kinquestion

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:

version: "2"

services:
  web:
    build: .
    networks:
      - foo

networks:
  foo:

All 3 comments

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:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

riquito picture riquito  ·  146Comments

jmmills picture jmmills  ·  146Comments

chymian picture chymian  ·  94Comments

ahmet2mir picture ahmet2mir  ·  131Comments

devinrsmith picture devinrsmith  ·  100Comments