I struggle to achieve the following:
I want two have two docker compose services (let's call them service_A and service_B), where
service_Aneeds to be in the host's network (i.e. runs withnetwork_mode=host) andservice_Bcan connect toservice_Avia its hostname, but it's also in the hosts network.
Here I made an example, which demonstrates what I want to achieve with postgres services as examples:
version: '3'
services:
service_A:
image: postgres
environment:
- POSTGRES_PASSWORD=password
network_mode: host
service_B:
image: postgres
depends_on:
- service_A
network_mode: host
command: psql postgresql://postgres:password@service_A:5432 --command "select * from pg_tables limit 1;"
But, when setting network_mode=host on service_A and service_B, service_B cannot reach service_A via its hostname. Is there an easy way to achieve that?
For those, who are interested why I need such a setup:
service_Afunctions as a proxy and logs into a VPN (via the docker host's connection)- and
service_Bshouldn't see the whole docker host, but needs to read fromservice_A, but be also responsive on the docker host.