Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make docker containers talk to a non-dockerized application?

I have a situation where docker containers have to talk to a non-dockerized application and docker containers in other host.

Let's say there are three servers A, B and C. Server A has two docker containers running JBoss App Server containers. Server B, a non-docker host has MySQL DB. Server C has another set of containers.

I want JBoss application server container to connect with MySQL DB residing in another host and pull information from the DB. JBoss also has to talk containers residing in Server C.

How to make this happen?

PS: I am new to Docker

like image 928
CK5 Avatar asked Jul 17 '17 10:07

CK5


1 Answers

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.

like image 86
Sreeni Avatar answered Oct 22 '22 08:10

Sreeni