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

Error connecting to MongoDB running in docker desktop #408

Open
steve1337 opened this issue Apr 13, 2022 · 5 comments
Open

Error connecting to MongoDB running in docker desktop #408

steve1337 opened this issue Apr 13, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@steve1337
Copy link

Hi all,

OS: Windows 10 21H2 (OS Build 19044.1620)
VSCode: 1.65.2
MongoDB Extension: 0.9.2
Docker Desktop: 4.6.1 (76265)

I just had some issue connecting to a MongoDB server running inside Docker Desktop on Windows 10.

I kept getting the following error: Unable to connect: getaddrinfo ENOTFOUND mongo1

I was able to fix this by adding the following entry to my hosts file: 127.0.0.1 mongo1

I don't have issues connecting to the DB via: mongoose, MongoDB Compass or NoSQLBooster for MongoDB
I also don't have issues connecting to clusters in Atlas

My local mongoDB is setup w/ this docker-compose.yaml

services:
    mongo1:
        hostname: mongo1
        container_name: localmongo1
        image: mongo:4.2.10
        expose:
            - 27017
        ports:
            - 27017:27017
        restart: always
        entrypoint: ["/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0", "--journal", "--dbpath", "/data/db", "--enableMajorityReadConcern", "false"]
        volumes:
            - ./storage/mongo/data1/db:/data/db 
            - ./storage/mongo/data1/configdb:/data/configdb
    mongo2:
        hostname: mongo2
        container_name: localmongo2
        image: mongo:4.2.10
        expose:
            - 27017
        ports:
            - 27018:27017
        restart: always
        entrypoint: ["/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0", "--journal", "--dbpath", "/data/db", "--enableMajorityReadConcern", "false"]
        volumes:
            - ./storage/mongo/data2/db:/data/db 
            - ./storage/mongo/data2/configdb:/data/configdb
    mongo3:
        hostname: mongo3
        container_name: localmongo3
        image: mongo:4.2.10
        expose:
            - 27017
        ports:
            - 27019:27017
        restart: always
        entrypoint: ["/usr/bin/mongod", "--bind_ip_all", "--replSet", "rs0", "--journal", "--dbpath", "/data/db", "--enableMajorityReadConcern", "false"]
        volumes:
            - ./storage/mongo/data3/db:/data/db
            - ./storage/mongo/data3/configdb:/data/configdb

Any ideas why it was necessary to add this entry to my hosts file?

@Anemy
Copy link
Member

Anemy commented Apr 13, 2022

@steve1337 to clarify - did all of the other clients mongoose, MongoDB Compass or NoSQLBooster for MongoDB, also require you to add the entry to the hosts file before you were able to connect? Or is this only with the VSCode extension?

@steve1337
Copy link
Author

steve1337 commented Apr 14, 2022

@Anemy
Only the VSCode extension required it

@Anemy
Copy link
Member

Anemy commented May 23, 2022

Created a ticket to track this, not sure on the cause off the top of my head so it'll take a bit of investigation. Could be a restriction or bug with our dns lookup we're using to connect in VSCode.
https://jira.mongodb.org/browse/VSCODE-331
I'll post back here when we've got an update on the ticket. For now it sounds like adding the host to the hosts file works as a workaround.

@albisco
Copy link

albisco commented Jun 2, 2022

I stumbled onto this issue myself today.

Reverting this extension back to 0.8.0 resolved this for me.

@Anemy
Copy link
Member

Anemy commented Jan 12, 2024

@steve1337 @albisco We've released a new version of the extension with a new connection form. Could you try creating this connection again and see if the error persists? Thanks for opening the issue, hopefully the recent changes have fixed this for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants