简体   繁体   中英

Docker - access to host network and docker network

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM