5

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

CK5
  • 1,055
  • 3
  • 16
  • 29

1 Answers1

5

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.

Sreeni
  • 748
  • 5
  • 6
  • Hi @Sreeni Is it not possible to do this in overlay mode? And one more query. What is the purpose of DNS flag in run command? Can I provide --dns flag in docker run command to point to the DB residing in Server B? – CK5 Jul 18 '17 at 09:18
  • hi Aditya, you can use overlay network to connect 2 containers, but you need to use bridge network to reach DB's ip. In overlay network, docker_gwbridge provides external connectivity. DNS flag allows you to use external DNS servers. By default, docker uses dns server in docker engine and for names it cannot find there, it uses host's DNS server. I have captured common Docker networking problems and solutions here(https://www.slideshare.net/SreenivasMakam/docker-networking-common-issues-and-troubleshooting-techniques). pls see if it helps. – Sreeni Jul 18 '17 at 11:30
  • Hi @Sreeni I have edited the original question. AFAIK, containers can be part of multiple networks. So containers in A and C servers can leverage overlay. While containers in A and MySQL DB can leverage user defined bridge network. Am I correct? But I am still confused how to make containers point to non-dockerized application? Is there any specific command to achieve this or is there any specific flag like --dns? I am sorry to come up with many questions :) – CK5 Jul 18 '17 at 14:42
  • hi @Aditya, I have updated my answer based on your question's update. Its difficult to add more text in the comments section.. – Sreeni Jul 18 '17 at 15:24
  • hi @Sreeni thank you very much for the guidance :) I will ping you if I encounter some doubts. – CK5 Jul 19 '17 at 03:08