在docker-compose中无法将2个网络附加到容器

时间:2017-07-26 13:57:59

标签: docker docker-compose

我需要将2个网络连接到容器,对于一个网络,我需要静态IP。 这是我的docker撰写文件:

version: '2'
services:
  # --------------------------------------------- Web app container
  webapp:
    networks:
      br0:
          ipv4_address: 172.16.238.10
      - bridge
    container_name: homer-webapp
    build: ./webapp/.
    image: sipcapture/homer-webapp
    restart: always

但它不起作用:

ERROR: yaml.parser.ParserError: while parsing a block mapping
  in "./docker-compose.yml", line 6, column 7
expected <block end>, but found '-'
  in "./docker-compose.yml", line 8, column 7

如果我只是连接一个网络,它会按预期工作。

如果我以下列方式连接2个网络,它也会起作用:

networks:
  - br0
  - bridge

这不起作用:

networks:
  - br0:
    - ipv4_address: 172.16.238.10
  - bridge

我收到错误消息:

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.webapp.networks contains {"br0": [{"ipv4_address": "172.16.238.10"}]}, which is an invalid type, it should be a string

任何提示?欢迎任何帮助!!!

1 个答案:

答案 0 :(得分:0)

这对我有用:

version: '2'
services:
  # --------------------------------------------- Web app container
  webapp:
    networks:
      br0:
        ipv4_address: 172.16.238.10
      bridgeCUSTOM:
    container_name: homer-webapp
    build: ./webapp/.
    image: sipcapture/homer-webapp
    restart: always
networks:
  br0:
    external: true
  bridgeCUSTOM:
    external: true

仍然不知道如何使用默认桥而不是bridgeCUSTOM来使用br0,但这对我来说并不是什么大问题。谢谢大家的帮助!