3

In "naked" Docker, I can use --network=host to make the host reachable from the container through the docker0 interface at 127.0.0.1, or I can reach the host at 172.17.0.1.

Ostensibly docker-compose supports the host networking driver through network_mode: host. Unfortunately, this prevents me from using exposed ports. Containers created using docker-compose don't live on the docker0 interface, and hence can reach the host at some IP address like 172.18.0.1 or 172.19.0.1, decided at startup.

Even once I know that address, it doesn't seem to be reachable from the container.

How can I connect from the container to the host?

Carl Patenaude Poulin
  • 6,238
  • 5
  • 24
  • 46
  • There are a couple of workarounds to this described in [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach?rq=1) and [How to get the IP address of the docker host from inside a docker container](https://stackoverflow.com/questions/22944631/how-to-get-the-ip-address-of-the-docker-host-from-inside-a-docker-container). The default gateway in the container's network will be the host. – David Maze Sep 22 '20 at 00:08
  • have you found a solution for this? – Emil Feb 25 '21 at 20:11

0 Answers0