I am working on an application to move it to Docker. The application has a reverse proxy nginx sitting at the front that directs the calls to the the front end application. The front end application is then linked to a back end java application. At the end there is a mongo db. I don't want to move mongo db to a container so want my application to communicate directly with the mongo db. I use docker-compose to bring my containers to life. My question is how can I make my containers to communicate with the mongo db using docker-compose. I have searched the and found the following link where it is being spoken about and plans to be added to Docker. However I couldn't find a solid example. I a new to docker so any help will be highly appreciated. https://github.com/docker/compose/issues/1110
Connect to other containerized services # Run server $ docker run --name mysql_server -d -p 3307:3306 -e MYSQL_ROOT_PASSWORD=password mysql # Run client $ docker run --rm --name my_client -it --link mysql_server:mysql_server alpine ping mysql_server > PING mysql_server (172.17. 0.5): 56 data bytes 64 bytes from 172.17.
Your Docker container can connect to the outside world, but the outside world cannot connect to the container. To make the ports accessible for external use or with other containers not on the same network, you will have to use the -P (publish all available ports) or -p (publish specific ports) flag.
First of all, it is a best practice to leave any persistent data outside the image, so you made a good decision with that ;).
So, to connect to a database that is on the host machine, follow these steps:
ip a
in the console if you are running some Linux distribution, or ipconfig /all
if you are running Windows. You can see the IP address next to the docker bridge adapter (if you are using the default adapter it should be docker0
and the row should be starting with inet
).That should do the job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With