Connecting to MongoDB from a Docker container

david's Avatar

david

05 Jun, 2020 11:37 PM

I am trying to connect to Mongo using mongodb://host.docker.internal:27017/database
Is Mongo running on port 27017 ?
If yes, what else may be the problem? I tried using 'localhost' as well, but the above connection string works on Windows locally.

Thanks,
David

  1. Support Staff 1 Posted by Feodor Fitsner on 05 Jun, 2020 11:53 PM

    Feodor Fitsner's Avatar

    Hi David,

    Mongo is not started by default. Start it with:

    net start MongoDB
    
  2. Support Staff 2 Posted by Feodor Fitsner on 06 Jun, 2020 12:45 AM

    Feodor Fitsner's Avatar

    It's bound to 127.0.0.1:27017, so it couldn't be accessed from a container unless configured to listen on all IPs: https://ci.appveyor.com/project/FeodorFitsner/simple-console#L21

    I'm changing the config and starting Mongo with this simple PS snippet:

    Add-Content -Path C:\MongoDB\mongod.cfg -Value "net:`n  bindIpAll: true"
    Start-Service mongodb
    
  3. 3 Posted by david on 06 Jun, 2020 01:05 AM

    david's Avatar

    still no luck for me, but I got mongo to work in docker which is even better because I can control the version of docker. Thanks for your help.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac