0
  1. I'm having docker container up and running by using the following command:

    docker run -p 27017:27017 -d mongo

Docker Logs for reference.

  1. Then I clone a github repo: https://github.com/springframeworkguru/spring-boot-mongodb.git
  2. Import the project in IntelliJ IDE, build it and run.

SpringBoot App Error Logs here

Issue : I'm not able to connect to the mongo app running in the container from my SpringBoot application as I'm getting MongoSocketOpenException as shown in the logs.

Any help is appreciated?

Docker version 18.03.0-ce, build 0520e24302

OS: Windows 10

Chethan B
  • 1
  • 3

2 Answers2

0

Docker for win has some problems with loopback interfaces.

https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/

Try run docker inspect and configure your application with the container address.

Jonathan Beber
  • 537
  • 1
  • 4
  • 16
  • Thanks, Jonathan for your inputs. I'm just getting started with Docker.So, I'm new to this. Could you give me an example with regards to configuration part for my application? – Chethan B Apr 16 '18 at 00:14
  • Can you please respond? – Chethan B Apr 18 '18 at 18:22
  • @ChethanB In your application you need to change the host address of mongoDB to the ip that `docker inspect` indicates to you. You should start with easier checkups to improve your debugging. Start with a simple telnet command, checking if your mongoDB is accepting connection in that port. For example `telnet localhost 27017`. – Jonathan Beber Apr 19 '18 at 18:10
  • Thanks for your inputs. I did configure the host address of my application to the docker container IP as shown here. `spring.data.mongodb.uri=mongodb://172.17.0.2:27017/test`. Still, I'm facing the same issue. I even tried telnet command to check if MongoDB is accepting connections. `telnet localhost 27017` No luck here too. Is this a container config problem? – Chethan B Apr 19 '18 at 21:54
  • So your container isn't accepting connection as localhost, try `telnet 172.17.0.2 27017`. – Jonathan Beber Apr 20 '18 at 18:09
  • `Connecting To 172.17.0.2...Could not open connection to the host, on port 27017: Connect failed` This too isn't accepting any connections. – Chethan B Apr 21 '18 at 18:34
  • Seems like your container isn't running – Jonathan Beber Apr 23 '18 at 14:19
  • The container is running. I've made sure to check the running containers through `docker ps` command – Chethan B Apr 24 '18 at 18:51
  • I'm able to connect to the mongo container. The mistake was I got the mongo container's IP instead of docker container's IP. Anyways thanks for your patience. Appreciate it. – Chethan B Apr 24 '18 at 19:05
0

Problem: I was trying to configure SpringBoot Application to mongo container IP which I retrieved from mongo inspect <mongo_container> command which was incorrect.

Solution: Configured my application using docker IP retrieved by docker-machine <env> which resolved the problem. Link to the post is here.

Chethan B
  • 1
  • 3