Network Overlay - Connection between two nodes doesn't work

Hello, I would like to have some help about Docker Swarm and Overlay networks.

I currently have two servers that connect to each other via their public IPs:

  • A: Hosting databases (Postgres) and my program manager, launched via a Docker Compose and replicas of my program, via Docker Swarm
  • B: Hosting only replicas of my program via Docker Swarm

To enable Server B to connect to Server A’s database, I thought of using an Overlay network, which I created before launching the Swarm & Compose containers.
When I start deploying replicas on Server A, they are indeed created on Server B as well, along with the overlay network.

On server A, the replicas manage to connect to the database via the container name, but the replicas can’t connect to it.

I looked via a docker network inspect "name of my network" on both servers, and I can see the name of the containers hosted by the server on which this command is run, but not that of the other machine.

Here’s a diagram of my problem:

Thanks for your help!

Show your full docker-compose.yml file(s).

Maybe check the simple Traefik Swarm example, use docker stack deploy to run.