Docker compose, running containers in net:host

后端 未结 5 2028
栀梦
栀梦 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: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
    

提交回复
热议问题