vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Error connecting to MongoDB running in docker desktop

Open steve1337 opened this issue 3 years ago • 5 comments
trafficstars

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?

steve1337 avatar Apr 13 '22 09:04 steve1337

@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?

Anemy avatar Apr 13 '22 19:04 Anemy

@Anemy Only the VSCode extension required it

steve1337 avatar Apr 14 '22 11:04 steve1337

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.

Anemy avatar May 23 '22 12:05 Anemy

I stumbled onto this issue myself today.

Reverting this extension back to 0.8.0 resolved this for me.

albisco avatar Jun 02 '22 05:06 albisco

@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.

Anemy avatar Jan 12 '24 15:01 Anemy