Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting Robo 3T to Docker MongoDB container

As part as an attempt to resolve a Hibernate OGM connection issue, I want to see if I connect from Robo 3T.

I build my MongoDB image and start it running.

docker ps:

MacBook-Pro:GoStopHandle NOTiFY$ docker ps CONTAINER ID IMAGE
COMMAND CREATED STATUS PORTS NAMES 0375a68b9988 gostophandlemongodb:latest
"docker-entrypoint.s…" 5 seconds ago Up 4 seconds
0.0.0.0:32844->27017/tcp goStopHandleMongo

The IP address of the containers is:

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 0375a68b9988 172.17.0.2

I've enter the 'mongo' shell:

docker exec -it goStopHandleMongo mongo admin

I add a user & password:

> db.createUser(
...   {
...     user: "NOTiFY",
...     pwd: "MyPassword",
...     roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
...   }
... )
Successfully added user: {
    "user" : "NOTiFY",
    "roles" : [
        {
            "role" : "userAdminAnyDatabase",
            "db" : "admin"
        },
        "readWriteAnyDatabase"
    ]
}

I then create a connection in Robo 3T: Robo 3T - create connection

I then set-up the 'Authentication':

Authentication

When I try & connect I get:

Connection dialog

Any suggestions?

like image 213
NOTiFY Avatar asked Apr 05 '19 14:04

NOTiFY


People also ask

How do I connect to a MongoDB Docker container?

For connecting to your local MongoDB instance from a Container you must first allow to accept connections from the Docker bridge gateway. To do so, simply add the respective gateway IP in the MongoDB config file /etc/mongod. conf under bindIp in the network interface section.

Can I use MongoDB in Docker?

Can MongoDB Run in a Docker Container? MongoDB can run in a container. The official image available on Docker Hub contains the community edition of MongoDB and is maintained by the Docker team. This image can be used in a development environment.

How does MongoDB run in Docker container from host?

You can connect to MongoDB on localhost:27017 . Then use the following command to open the MongoDB shell. I have used mymongo as an arbitrary container name, though you can replace mymongo with test-mongo or any other container name of your choosing. The show dbs command will display all your existing databases.


Video Answer


1 Answers

It wasn't until I had to reboot my Mac that I realised that I'd still had a local instance of MongoDB running, therefore the I wasn't connecting to my Docker instance of MongoDB but my local (Brew installed) instance.

Once I'd seen @Artjom Zabelin answer here and "Don't forget to map port to host port"

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

It connected to MongoDB running my container.

@Frank Yucheng Gu was correct that I needed 'localhost'.

like image 92
NOTiFY Avatar answered Oct 18 '22 22:10

NOTiFY