Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker - access to host network and docker network

Tags:

docker

centos

I have a docker container and I want to give it --network=host AND --network=postgres. I need to connect to the host network in order to use the host datadog server (UDP) and the postgres network for its database.

Trying to add both network results in docker: conflicting options: cannot attach both user-defined and non-user-defined network-modes..

Any idea what's the correct way to handle this?

like image 700
TheUnreal Avatar asked Oct 17 '25 17:10

TheUnreal


1 Answers

You could use the the IP address of the host machine from within you container in order to send requests to the host machine.

A better solution, however, would be to use --add-host=host.docker.internal:host-gateway or

extra_hosts:
    - host.docker.internal:host-gateway

where host.docker.internal is then the host name of the host network inside your docker container. This name can of course be changed to your liking.

Credit: https://medium.com/@TimvanBaarsen/how-to-connect-to-the-docker-host-from-inside-a-docker-container-112b4c71bc66

like image 147
David Möller Avatar answered Oct 20 '25 11:10

David Möller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!