Docker compose, running containers in net:host

后端 未结 5 2029
栀梦
栀梦 2020-12-13 01:34

I want to spawn 3 services in the "host" net using docker-compose. Here is my docker-compose.yml file:

version: \'2\'
services:
  mysql:
    image:          


        
相关标签:
5条回答
  • 2020-12-13 02:19

    you can try just add

    network_mode: "host"
    

    example :

    version: '2'
    services:
      feedx:
        build: web
        ports:
        - "127.0.0.1:8000:8000"
        network_mode: "host"
    

    list option available

    network_mode: "bridge"
    network_mode: "host"
    network_mode: "none"
    network_mode: "service:[service name]"
    network_mode: "container:[container name/id]"
    

    https://docs.docker.com/compose/compose-file/#network_mode

    0 讨论(0)
  • 2020-12-13 02:25

    Maybe I am answering very late. But I was also having a problem configuring host network in docker compose. Then I read the documentation thoroughly and made the changes and it worked. Please note this configuration is for docker-compose version "3.7". Here einwohner_net and elk_net_net are my user-defined networks required for my application. I am using host net to get some system metrics.

    Link To Documentation https://docs.docker.com/compose/compose-file/#host-or-none

    version: '3.7'
    services:
      app:
        image: ramansharma/einwohnertomcat:v0.0.1
        deploy:
          replicas: 1
          ports:
           - '8080:8080'
        volumes:
         - type: bind
           source: /proc
           target: /hostfs/proc
           read_only: true
         - type: bind
           source: /sys/fs/cgroup
           target: /hostfs/sys/fs/cgroup
           read_only: true
         - type: bind
           source: /
           target: /hostfs
           read_only: true
        networks:
         hostnet: {}
        networks:
         - einwohner_net
         - elk_elk_net
    networks:
     einwohner_net:
     elk_elk_net:
       external: true
     hostnet:
       external: true
       name: host
    
    0 讨论(0)
  • 2020-12-13 02:26

    Those documents are outdated. I'm guessing the 1.6 in the URL is for Docker 1.6, not Compose 1.6. Check out the correct syntax here: https://docs.docker.com/compose/compose-file/#network_mode. You are looking for network_mode when using the v2 YAML format.

    0 讨论(0)
  • 2020-12-13 02:27

    delete the warn config option for services.app: 'net', it will can work.

    0 讨论(0)
  • 2020-12-13 02:29

    Just print

    network_mode: "host"

    0 讨论(0)
提交回复
热议问题