Docker错误:仅“ host”的一个实例允许网络 [英] Docker ERROR: only one instance of "host" network is allowed

查看:2129
本文介绍了Docker错误:仅“ host”的一个实例允许网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to run a container where I need to user network driver as "host" instead of "bridge". I am running it on Centos machine and my docker-compose.yml is

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 时,出现以下错误> :

But i am getting the following error when I fire "docker-compose up" :


错误:只有 host的一个实例允许网络

ERROR: only one instance of "host" network is allowed

有人可以建议我如何使用docker-compose.yml使用主机网络。

Can anyone please suggest how can I use host network using docker-compose.yml.

还要注意,如果按照@larsks的建议使用network_host,我仍然会收到错误消息

Also note that if I use network_host as suggested by @larsks, I am still getting error

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'

ERROR: The Compose file './docker-compose.yml' is invalid because: Unsupported config option for services: 'testContainer'


推荐答案

摆脱网络部分您的 docker-compose.yml ,然后添加 network_mode 指令指向您的服务定义:

Get rid of the networks section in your docker-compose.yml, and add a network_mode directive to your service definition:

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错误:仅“ host”的一个实例允许网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆