services communication

I’m trying to solve an issue i have.
i have 4 services, two of them have network mode host on docker compose, and the other two dont.

how should the services communicate with each other (every service has a grpc server and the communicate by grpc).
the one who dont have network mode host, are communicating by service name and that works fine.
i’m not sure how to communicate between services while the system is offline and not connected to the internet. (our device works offline and gets connected in later use)


Hey @mellerdaniel, communication between containers in host networking is a known friction point in Docker but there are a few workarounds we can explore.

As for your grpc servers, do all containers have a grpc server binding to the same port, or are they using unique ports? I would expect the two services in host networking to collide if they are binding to a port.

There are ways to dynamically determine the Host bridge address from inside a service, so if something on the host is listening on port xyz you should be able to reach it in the container via for example.

thanks for the fast response.
what about two containers that 1 is not on network host and the other one is?
or should i move every container to be host?

It really depends how your GRPC application works. The two containers won’t be able to discover each other as they are on different subnets, but if the GRPC service is binding to a port we may be able to map host port to container bridge ports for communication. Do you specify a port for binding when running your GRPC service?

services that are not on host networking are using the same port number, and host networking uses different ports.

Okay, cool, we can work with that. So consider this:

  • serviceA in host networking with GRPC on port 123
  • serviceB in host networking with GRPC on port 456
  • serviceC in bridge networking with GRPC on port 789
  • serviceD in bridge networking with GRPC on port 789

If you adjust services C and D to expose unique ports on the host via the ports: option they can stay in bridge networking and then we have 4 unique GRPC ports on the host.

  • serviceA with GRPC on host port 123 (still in host mode)
  • serviceB with GRPC on host port 456 (still in host mode)
  • serviceC with GRPC on host port 321 (still in bridge mode)
  • serviceD with GRPC on host port 654 (still in bridge mode)

From there, the services A and B can communicate to any of the 4 services via

For services C and D you can lookup their internal bridge IP via ip addr show wlan0 | grep -Po 'inet \K[\d.]+' and change the last octet to .1. For example you may end up with but this can change so it should be scripted.

I hope this helps!

Hey @mellerdaniel ,

Have you had the chance to try Kyle’s suggestion? Let us know how it went.


it worked!

That’s great news.