CONNECTING AN APPLICATION TO DATABASE USING DOCKER NETWORK
The project is about connecting an application to a database using a docker network, in this project above i deploy and run an application and a database container on a docker server or engine, after which i created a docker network to link the 2 docker containers.
So in the above when the user : aye-akamara try to access the application, the docker server does the port forwarding and route the traffic to the application container. The question is how this app talks to the database, there must be a communication. The communication is made possible with the aid of a docker network and environmental variables. Note that for two containers to communicate they have to be in the same network.
I used the below to deploy and run spring app application and connect it to the mongodb database.
deploy stateless applications:
docker run --name spingapp -d -p 80:8080 --network fintech \
-e MONGO_DB_USERNAME=devdb -e MONGO_DB_PASSWORD=dev@123 \
-e MONGO_DB_HOSTNAME=mongodb mylandmarktech/spring-boot-mongo
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
mongo database:
deploy statefull applications:
docker run -d --network fintech --name mongodb \
-e MONGO_INITDB_ROOT_USERNAME=devdb \
-e MONGO_INITDB_ROOT_PASSWORD=dev@123 mongo
http://3.237.92.35/
Note : to create a docker network, you can use the command docker network create name