Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not connecting to local mongo db #66

Open
bhiwagade-rahul opened this issue Aug 26, 2020 · 9 comments
Open

Not connecting to local mongo db #66

bhiwagade-rahul opened this issue Aug 26, 2020 · 9 comments

Comments

@bhiwagade-rahul
Copy link

After docker-compose up command, I am getting this error

Exception in monitor thread while connecting to server localhost:27017
klov | com.mongodb.MongoSocketOpenException: Exception opening socket
klov | at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)
klov | at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128)

I checked /usr/local/var/log/mongodb/mongo.log and mongo server I don't see any connection request. Can you please tell me what I am doing wrong?

Mac - Catalina 10.15.6
mongo - [email protected]

@bhiwagade-rahul
Copy link
Author

docker-compose file

version: '2'
services:
klov:
image: anshooarora/klov:1.0.1
container_name: klov
environment:
- SPRING_DATA_MONGODB_URI=mongodb://127.0.0.1:27017
ports:
- 80:80

@chipheolm
Copy link

I got a similar problem on MacOS.
My workaround :
fix docker-compose file:
- SPRING_DATA_MONGODB_URI=mongodb://host.docker.internal:27017
Hope it can help you.

@Naga911
Copy link

Naga911 commented Oct 21, 2020

@chipheolm ur code worked, thank you so much, i made mistake not providing "host.docker.internal", provided as localhost and finally its working, extremely happy- thank you for the help bro 👍

@akiladevraj
Copy link

i was facing problem , klov page was displaying blank, i changed in my docker file as "host.docker.internal", and to my surprise it worked :D . thanks a ton

@Kislaya1
Copy link

Kislaya1 commented Dec 17, 2021

Hi @anshooarora,

I tried the above approach but still while running the docker-compose file I am getting issue as below : -

`host.docker.internal:27017] com.mongodb.diagnostics.logging.SLF4JLogger: Exception in monitor thread while connecting to server host.docker.internal:27017

com.mongodb.MongoSocketOpenException: Exception opening socket

at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)

at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128)

at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)

at java.lang.Thread.run(Thread.java:748)

Caused by: java.net.ConnectException: Connection refused (Connection refused)

at java.net.PlainSocketImpl.socketConnect(Native Method)

at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)

at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)

at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)

at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)

at java.net.Socket.connect(Socket.java:589)

at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64)

at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79)

at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65)

... 3 common frames omitted`

Can you please help me out.

Also need to ask if we need to download mongodb seperately or will your docker compose yml will take care of that ?

Docker Compose YML as : -

version: '2'
services:
klov:
image: anshooarora/klov:1.0.1
container_name: klov
environment:
- SPRING_DATA_MONGODB_URI=mongodb://host.docker.internal:27017
ports:
- 80:80

@Kislaya1
Copy link

Kislaya1 commented Dec 17, 2021

Had tried with below Docker Compose File as well as thought to install mongodb seperately, but no luck with that. Same error log , @anshooarora can please help me.

version: '2'
services:
db:
image: mongo:3.2.0
container_name: mongo-db3
environment:
- PUID=1000
- PGID=1000
ports:
- "27017:27017"
restart: on-failure

klov:
image: anshooarora/klov:1.0.1
container_name: klov
expose:
- "80"
ports:
- "80:80"
depends_on:
- db
environment:
- SPRING_DATA_MONGODB_URI=mongodb://mongo-db3:27017

@Naga911
Copy link

Naga911 commented Dec 17, 2021 via email

@Kislaya1
Copy link

Kislaya1 commented Dec 17, 2021

hi 1. u need to download mongodb separately 2.yml/.yaml file takes image from dockerhub and checks for connection between klov and mongodb version: '2' services: klov: image: anshooarora/klov:1.0.1 container_name: klov environment: - SPRING_DATA_MONGODB_URI=mongodb://host.docker.internal:27017 ports: - 85:80 Regards, Nagaraj

On Fri, Dec 17, 2021 at 3:39 PM Kislaya Pant @.> wrote: Had tried with below Docker Compose File as well, but no luck with that. @anshooarora https://github.com/anshooarora can please help me. version: '2' services: db: image: mongo:3.2.0 container_name: mongo-db3 environment: - PUID=1000 - PGID=1000 ports: - "27017:27017" restart: on-failure klov: image: anshooarora/klov:1.0.1 container_name: klov expose: - "80" ports: - "80:80" depends_on: - db environment: - SPRING_DATA_MONGODB_URI=mongodb://mongo-db3:27017 — Reply to this email directly, view it on GitHub <#66 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALK2UZRJ3BO6KRO67WRNHN3URMD6LANCNFSM4QLV5QAA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you commented.Message ID: @.>

Hi Nagaraj

I had tried to use docker-compose yml file and tried to in-cooperate both mongo db and Klov server there.
But was facing same issue again. Can you please help me here ?

My Docker Compose YML file

version: '2'
services:
mymongo:
image: mongo:3.2.0
volumes:
- ./_data:/data/db
ports:
- "27017:27017"
restart: on-failure

klov:
image: anshooarora/klov:1.0.1
container_name: klov
depends_on:
- mymongo
environment:
- SPRING_DATA_MONGODB_URI=mongodb://host.docker.internal:27017
ports:
- 80:80

Can you please help me.

Thanks
Kislaya

@RomanRD
Copy link

RomanRD commented Aug 13, 2023

hi 1. u need to download mongodb separately 2.yml/.yaml file takes image from dockerhub and checks for connection between klov and mongodb version: '2' services: klov: image: anshooarora/klov:1.0.1 container_name: klov environment: - SPRING_DATA_MONGODB_URI=mongodb://host.docker.internal:27017 ports: - 85:80 Regards, Nagaraj

On Fri, Dec 17, 2021 at 3:39 PM Kislaya Pant @.> wrote: Had tried with below Docker Compose File as well, but no luck with that. @anshooarora https://github.com/anshooarora can please help me. version: '2' services: db: image: mongo:3.2.0 container_name: mongo-db3 environment: - PUID=1000 - PGID=1000 ports: - "27017:27017" restart: on-failure klov: image: anshooarora/klov:1.0.1 container_name: klov expose: - "80" ports: - "80:80" depends_on: - db environment: - SPRING_DATA_MONGODB_URI=mongodb://mongo-db3:27017 — Reply to this email directly, view it on GitHub <#66 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALK2UZRJ3BO6KRO67WRNHN3URMD6LANCNFSM4QLV5QAA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you commented.Message ID: _@**.**_>

Hi Nagaraj

I had tried to use docker-compose yml file and tried to in-cooperate both mongo db and Klov server there. But was facing same issue again. Can you please help me here ?

My Docker Compose YML file

version: '2' services: mymongo: image: mongo:3.2.0 volumes: - ./_data:/data/db ports: - "27017:27017" restart: on-failure

klov: image: anshooarora/klov:1.0.1 container_name: klov depends_on: - mymongo environment: - SPRING_DATA_MONGODB_URI=mongodb://host.docker.internal:27017 ports: - 80:80

Can you please help me.

Thanks Kislaya

Hi Kislaya1! I would really appreciate if you could tell how you solved this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants