Docker container interacting with an external database

I am working on an application to move it to Docker. The application has a nginx reverse proxy sitting at the front that routes calls to the front end application. The front end application is then linked to the java application on the rear panel. At the end there is mongo db. I do not want to translate mongo db into a container, so I want my application to directly communicate with mongo db. I use docker-compose to spice up my containers. My question is how can I make my containers to communicate with mongo db using docker-compose. I searched and found the following link mentioned, and plans to add to Docker. However, I could not find a convincing example. I'm new to dockers, so any help would be greatly appreciated. https://github.com/docker/compose/issues/1110

+4
source share
1 answer

First of all, it is better to discard any persistent data outside the image, so you made a good decision with that;).
Thus, to connect to the database located on the host machine, follow these steps:

  • First you need to find the IP address of the host machine in the docker network. You can do this by typing ip ain the console if you are using any Linux distribution, or ipconfig /allif you are using Windows. You can see the IP address next to the docker bridge adapter (if you use the default adapter, it should be docker0, and the line should start with inet).
  • Then, make sure that the database user does not have restrictions for connecting through an external network.
  • (IP-), , , .

.

+1

Source: https://habr.com/ru/post/1668368/


All Articles