Cannot connect to MySQL/PostgreSQL from Apache

Hello,

I have created a docker swarm on multiple dedicated servers and on each server i have multiple docker containers running.

I have a MySQL docker container part of the swarm running on server with name ds3. When i run also an apache container on same server ds3, then some conflict happens on networking level (i guess), because the application on apache container cannot connect to MySQL server, or if it connects it randomly gets connection refuse.

Apache containers from the other servers connect without problem to MySQL server. The problem happens only and only when both containers are on same machine.

I was able to reproduce the same problem with connection to PostgreSQL and also Elasticsearch.

Same problem happens also if MySQL or any other service runs directly on host server with opened port so apache container from same server to be able to access it, but then again same problem happens.

Right now I run MySQL/PostgreSQL, Elastic on one machine and webapps on the others so I can use docker containers for all without problems, but I will be very happy if I can still solve this weird problem.

I use overlay network for all containers.

I checked a lot and I am still not able to find a solution for this problem. I will be happy if you give me some ideas how I can solve this problem. Maybe I miss something in networking part.

Thanks and regards,
Ali Nebi