4

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.

3
  • Note that you say "dockerfile" but this isn't a Dockerfile but a Docker Compose file.
    – muru
    Mar 1, 2021 at 7:38
  • Yup, that was my bad I got confused. Will change it Mar 1, 2021 at 8:39
  • can we do this with a Dockerfile. ?
    – Noushad
    Apr 27, 2021 at 12:44

1 Answer 1

5

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.

4
  • Oh, thank you sir! Mar 1, 2021 at 7:26
  • can we achieve the same using a Dockerfile ?
    – Noushad
    Apr 27, 2021 at 12:44
  • @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.
    – muru
    Apr 28, 2021 at 9:33
  • @muru Alright, thanks a lot for the clarification
    – Noushad
    Apr 29, 2021 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.