8

I am using docker image https://hub.docker.com/_/mongo/ (Latest MongoDB version)

I run command

docker run --name some-mongo -d mongo

Then I install Studio 3T I enter connection information like this

enter image description here

but I can't connect. What is correct connection must declare in Studio 3T in this case? How to connect MongoDB instance (docker) by Studio 3T?

Vy Do
  • 46,709
  • 59
  • 215
  • 313

6 Answers6

12

You need to export the port you want to use in your docker command. e.g.

docker run -p 127.0.0.1:27017:27017 --name some-mongo -d mongo

This opens the port of the container on your host machine.

Rick Rongen
  • 719
  • 5
  • 10
  • I can connect to to my docker mongo via Robo 3T but not Studio 3T (I've imported the connection from Robo) But it can't connect – dragonalvaro Apr 23 '18 at 08:45
  • This is not working for me. I get "Fail to load list of databases" as a result of a login attempt. – fabien Dec 29 '19 at 17:47
  • @Rick Ronger How can this command be used with docker-compose? I'm quite new to all and very confused? – lomse Apr 20 '20 at 00:26
  • @lomse you can use this tool to convert ithttps://bucherfa.github.io/dcc-web/ (I recommend removing the name, as docker compose has a build in system for managing container names. – Rick Rongen Apr 20 '20 at 08:46
  • @dragonalvaro and fabien these errors are quite generic, they can have multiple causes. I suggest searching for them, as they are probably already asked once. – Rick Rongen Apr 20 '20 at 08:48
6
  • Click New Connection

  • Enter the Connection name

  • Click on From URI

  • Enter the URI in the following format mongodb://{username}:{password}@{ip_address}:{port}/?authSource=admin

  • Click OK

  • Click Test Connection

  • Works?

    • No: Check your username, password, etc
    • yes: Congrats!
Lone Ronin
  • 2,530
  • 1
  • 19
  • 31
0

You need to find the IP address where the Docker container is running. On Mac docker runs in the background inside a linux VM that has its own IP. Thus localhost will not work.

To find the IP, run docker-machine env default and set this IP in the Server field.

yamenk
  • 46,736
  • 10
  • 93
  • 87
0

for those on windows kindly check in task manager and make sure you don't have a local installation of mongo db server running then use localhost in address/connection string

Nelson Bwogora
  • 2,225
  • 1
  • 18
  • 21
0

I was running mongodb with wsl2 and docker, so I needed just to add "from uri", and set up ip_adress with the ip from wsl2.

Explanation:

  1. Uri: This connection string is the way we can talk to robo 3t understand how to connect with our mongodb server.
  2. ip_address: Because of docker creates containers that are similar to servers, each container has an ip_adress, so to have access to this mongodb server, we need to find the ip_adress from the container that we need.

I used this URI:

mongodb://{username}:{password}@{ip_address}:{port}/?authSource=admin

username = MONGO_INITDB_ROOT_USERNAME

password = MONGO_INITDB_ROOT_PASSWORD

port = 27017(docker container port will be set up on docker parameter "-p")

ip_address = Ip from wsl2 in my case, or localhost if you running docker locally.

This was my command to run the container on the first time :

docker container run -d -e MONGO_INITDB_ROOT_USERNAME=mongouser -e MONGO_INITDB_ROOT_PASSWORD=mongopwd -p 27017:27017 -v mongo_vol:/data/db mongo:4.4.3

Gabriel Silva
  • 51
  • 1
  • 5
0

I had a problem connecting Studio 3T with MongoDB earlier this week, and it consumed my entire working day, so I gave up on using Studio 3T to ensure time for other things and an alternative. Today I found this short video tutorial by Studio 3T on how to connect Studio 3T with MongoDB. Following the directions, I was surprised that a connection was made successfully.

I recommend you watch/follow this video: https://www.youtube.com/watch?v=_Ka3-HGNlYE

If it helps you, remember to tick this answer.

mathems32
  • 115
  • 9