Containers in bridge/user-defined bridge network can access outside world automatically. This happens through IP masquerading and Docker takes care of it.
- mysql db is in server B
- server A has a route to reach server B where mysql db is running.
- 2 containers are in server A
assuming the above, the 2 containers should be able to reach mysql db.
There is another related frequently asked question about containers accessing service in localhost. You can refer that discussion here(From inside of a Docker container, how do I connect to the localhost of the machine?)
Answer to updated question:
When you put container in overlay network in swarm mode, it also creates a bridge network(docker_gwbridge). This bridge is created by default for external access. You are correct that in this case, container is part of overlay and bridge network. Using overlay network, containers in server A can talk to containers in server C. For container in server A to reach DB(non-containerized application), you just need the IP address and port of the DB which you can directly access from inside container. As long as the DB IP address is reachable from server A, it will also be accessible from inside the container running in server A using the bridge network. You dont need any special DNS flag or anything else.