0

Unable to connect sailsJs dockerimage to mongodb. I am having issue while connecting mongodb running on local machine, not as mongo image.

mongodb is running on localhost:27017

error: Error: Failed to connect to MongoDB.  Are you sure your configured Mongo instance is running?

 Error details: {
     Error: connect ECONNREFUSED 127.0 .0 .1: 27017
     at Object.exports._errnoException(util.js: 1020: 11)
     at exports._exceptionWithHostPort(util.js: 1043: 20)
     at TCPConnectWrap.afterConnect[as oncomplete](net.js: 1090: 14)
     name: 'MongoError',
     message: 'connect ECONNREFUSED 127.0.0.1:27017'
 }
tgogos
  • 23,218
  • 20
  • 96
  • 128

1 Answers1

0

If the container is running in a docker engine in the same host where your MongoDB server is running, you should try to run your docker container using --net=host if you want your container to be able to reach 127.0.0.1/localhost in the same host. I nice answer can be found here.

If you're using docker engine in a VM you may have to change the localhost IP for the public/private IP assigned to your mongodb server host.

Miguel A. C.
  • 555
  • 6
  • 11