Hy, I am pretty new to docker and I am having some issue understanding how containers interact with each other in the docker world created using a docker compose
I have a docker-compose.yaml file that contain 2 services:
- A MongoDB service which is suppose to create a MongoDB database
- A Node.js app service that is trying to connect to that MongoDB database
When i try to run the docker-compose up command I get an error letting me know there was a issue connecting to my MongoDB instance.
info: Listening on port 3000...
error: uncaughtException: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
name: 'MongoNetworkError'
This is my docker-compose.yaml file
version: '3.7'
services:
mongodb:
container_name: mongodb_container
image: mongo:latest
ports:
- 27017:27017
volumes:
- mongodb_data_container:/data/db
my_app:
container_name: my_app_container
image: my_app:1.0
ports:
- 3000:3000
Can anyone help me out with this issue?