Piu130 Piu130 - 10 months ago 138
Node.js Question

Docker mongo image 'Connection refused' from other container

I'm new to docker. I'm trying to create a MongoDB container and a NodeJS container. My file looks like this.

It should run

npm install
and then
node .
docker-compose up
ends up with
[MongoError: connect ECONNREFUSED]
while the command
node .
I think this is because of the
bind_ip =
in the file
. Is this right?

I use boot2docker on a Win10 system.

How can I solve this problem so that node can connect to the MongoDB?

Answer Source

In your backend app, connect to mongodb:27017 instead of Where 'mongodb' is the name of your container within docker-compose.yml.