Docker mongo image 'Connection refused' from other container

I recently encountered similar issue. I am running docker toolbox under win 10 and this is how it worked for me:

1) I had to verify which URL my default docker machine is using. This can be checked by running docker-machine ls command. It will list available machines:

NAME             ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
default          *        virtualbox   Running   tcp://192.168.99.100:1234           v17.06.0-ce
rancher-client   -        virtualbox   Stopped                                       Unknown
rancher-server   -        virtualbox   Stopped                                       Unknown

2) When running mongodb image specify the port mapping

docker run -d -it -p 27017:27017 mongo

3) At that point the valid mongo url would look something like this

var dbhost = 'mongodb://192.168.99.100:27017/test

where 192.168.99.100 was the default machine URL from the point 1)

Hope it helps someone.


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


Most likely, yes. 127.0.0.1 points to localhost inside the mongodb container, so is not accessible from outside the container. Binding to 0.0.0.0 will probably work.

With the link you specified in the docker-compose.yml, your backend container should then be able to connect to the mongo container through mongodb:27017