1

I have a docker compose file with two services. One service exposes a port and is configured in the (default) bridge network mode. The other service needs to connect to the exposed port and has to be in the host network mode.

How can I make the "host network" service connect to a port exposed by the "bridge network" service? localhost, 127.0.0.1, or the name of the service does not work.


Currently I am using:

  • Docker version 20.10.21
  • Docker Compose version v2.11.1
  • Docker Compose file version 3.5
Lars Schneider
  • 5,530
  • 4
  • 33
  • 58
  • 1
    IME, host networking is rarely necessary. Can you change the setup so that both containers are using normal Docker networking, and then can use normal Docker DNS? – David Maze Nov 24 '22 at 12:36
  • (Host networking essentially disables Docker's entire networking system, so if you want to connect to another container you're "outside Docker" for networking purposes. Also see for example [How to use the host network, and any other user-defined network together in Docker-Compose?](https://stackoverflow.com/questions/47303141/how-to-use-the-host-network-and-any-other-user-defined-network-together-in-dock)) – David Maze Nov 24 '22 at 12:41
  • @DavidMaze unfortunately host is necessary for mdns. I could try to work around this, but this opens another can of worms. I tried the solution mentioned in the linked question but no success :-( – Lars Schneider Nov 24 '22 at 19:09

0 Answers0