0

I have a microservice developed with spring boot that connects with a mongodb. When a run it local, everything is ok. When I create a docker container to my microservice, but NOT to my mongodb, I receive an error of "connection refused". I was connecting to my mongodb at "localhost:27017", and then "127.0.0.1:27017", but both doesn't work. I know that the problem is this address because docker uses a network adapter different from the server, but I can't find how to configure to my spring boot container connects with my mongodb local. Is this approach wrong? I don't wanna to dockerize my mongodb because in the future the application will not be together with my database.

I'm using a Linux Ubuntu.

1 Answers1

1

Use your real IP address instead. Localhost addresses will resolve to the container itself.

Paulo Pedroso
  • 3,555
  • 2
  • 29
  • 34
  • Thanks Paulo! In [this](https://stackoverflow.com/questions/31324981/how-to-access-host-port-from-docker-container) link, I found my answer! – arturcosta88 Apr 04 '19 at 22:07
  • Thank you for pointing the answer. It's very thorough. I mainly use Docker in the development stages and using the host IP address also works, but the pointed solution is far more independent. – Paulo Pedroso Apr 05 '19 at 16:52
  • Yes, I liked the pointed solution too! – arturcosta88 Apr 06 '19 at 17:16