equivalent of --net=host in docker compose file when creating docker container

5,726

Use network_mode instead:

network_mode

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

network_mode: "bridge"
network_mode: "host"
network_mode: "none"

You can use networks to specify host networking in swarm mode, by setting the driver of a given network to host.

Share:
5,726

Related videos on Youtube

user13539846
Author by

user13539846

Updated on September 18, 2022

Comments

  • user13539846
    user13539846 over 1 year

    I trieddocker run --net=host -d --name pdns-recursor pschiffe/pdns-recursor and it works. Now my goal is to use dockerfile to pass some environment without errors.

    I tried:

    networks:
      name: host
    

    and

    networks:
      name: "host"
    

    and also the examples indicated here.

    I always get an The Compose file './docker-compose.yml' is invalid because: services.recursor.networks.name contains an invalid type, it should be an object, or a null.

    Any suggestions are much appreciated.

    • muru
      muru about 3 years
      Note that you say "dockerfile" but this isn't a Dockerfile but a Docker Compose file.
    • user13539846
      user13539846 about 3 years
      Yup, that was my bad I got confused. Will change it
    • Noushad
      Noushad about 3 years
      can we do this with a Dockerfile. ?
  • user13539846
    user13539846 about 3 years
    Oh, thank you sir!
  • Noushad
    Noushad about 3 years
    can we achieve the same using a Dockerfile ?
  • muru
    muru about 3 years
    @Noushad no, there's nothing similar in the Dockerfile instructions. It might be possible by some custom Dockerfile syntax, but I don't know of any.
  • Noushad
    Noushad about 3 years
    @muru Alright, thanks a lot for the clarification