【问题标题】:Docker ERROR: only one instance of "host" network is allowed [duplicate]Docker错误:只允许一个“主机”网络实例[重复]
【发布时间】:2020-09-07 12:28:43
【问题描述】:

我正在尝试运行一个容器,我需要将网络驱动程序作为“主机”而不是“桥”来使用。我在 Centos 机器上运行它,我的 docker-compose.yml 是

version: '3.4'

services:
  testContainer:
    build:
      context: .
      args: 
        HADOOP_VERSION: 2.6.0
        HIVE_VERSION: 1.1.0
    image: testcontainer
    container_name: testcontainer
    hostname: testcontainer
    ports:
      - 9200:9200
      - 9300:9300
      - 5601:5601
      - 9001:9001
    ulimits:
      memlock:
        soft: -1
        hard: -1  
    networks:
      - elknet  

networks:
  elknet:
    driver: host      

但是当我触发“docker-compose up”时出现以下错误:

错误:只允许一个“主机”网络实例

谁能建议我如何使用 docker-compose.yml 使用主机网络。

另请注意,如果我按照@larsks 的建议使用 network_host,我仍然会收到错误

version: '3.4'

services:
  testContainer:
    build:
      context: .
      args: 
        HADOOP_VERSION: 2.6.0
        HIVE_VERSION: 1.1.0
    image: testcontainer
    container_name: testcontainer
    hostname: testcontainer
    ports:
      - 9200:9200
      - 9300:9300
      - 5601:5601
      - 9001:9001
    ulimits:
      memlock:
        soft: -1
        hard: -1  
    network_mode: host

我收到以下错误

错误:撰写文件“./docker-compose.yml”无效,因为: 服务不支持的配置选项:'testContainer'

【问题讨论】:

    标签: docker docker-compose centos7 docker-swarm


    【解决方案1】:

    去掉docker-compose.yml 中的networks 部分,并在服务定义中添加network_mode 指令:

    services:
      testContainer:
        build:
          context: .
          args: 
            HADOOP_VERSION: 2.6.0
            HIVE_VERSION: 1.1.0
        image: testcontainer
        container_name: testcontainer
        hostname: testcontainer
        ports:
          - 9200:9200
          - 9300:9300
          - 5601:5601
          - 9001:9001
        ulimits:
          memlock:
            soft: -1
            hard: -1  
        network_mode: host
    

    【讨论】:

    • @Iarsks 当我使用“network_mode: host”时抛出这个错误---> 错误:Compose 文件 './docker-compose.yml' 无效,因为:不支持的服务配置选项: 'testContainer'
    • 看起来您正在使用具有不同行为的 Docker Swarm。您的问题已链接到具有您需要的答案的副本。
    猜你喜欢
    • 2017-10-09
    • 2022-08-08
    • 1970-01-01
    • 2012-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多