I have built three docker images of node, elastic search, and mongo. Then pushed those to docker hub. after pulling those images, I am running them using the command docker run. They are running successfully. But the node app is not being able to connect to mongo or elastic. I have tried creating a network and adding the containers to it, but it doesn’t help. Can someone help regarding the issue?
2
Answers
It depends on where the individual containers are running. If they are running on the same host, you can connect them to the same bridge network.
Refer here: https://docs.docker.com/network/bridge/
If they are running on different host, you would have to use host networking and expose the relevant ports. Refer here: https://docs.docker.com/network/host/
when working with multiple containers it’s better to use Docker compose.
you can create a docker-compose.yml file defining services(your containers) there.
Here is an example docker-compose.yml for node,mongo and elasticsearch
Your question is not clear so I cant answer more than that