Search code examples
linuxdockernetwork-programmingdocker-composeredhat

how to use host network config using docker-compose


I'm trying to use server(host) network setting for docker container also. I'm able to do it using docker run command but not able to do it using docker-compose. I'm trying to achieve same behaviour as the command -

sudo docker run -p 8001:8001 -d --network host --name container_name image_name

using docker-compose. All the solution I found in internet are not working.

here is my docker-compose.yml

version: '3.4'

services:

    e-si:
        build: ./path/to/project
        networks : host
        ports:
            - 8001:8001
        volumes:
            - /server/location:/container/location

Can anyone tell me what I'm doing wrong?

Thanks in advance.


Solution

  • Use network_mode:

    Network mode. Use the same values as the docker client --network parameter, plus the special form service:[service name].

    version: '3.4'
    services:
      e-si:
        build: ./path/to/project
        network_mode: "host"
        volumes:
          - /server/location:/container/location