1

I am trying to setup a local Mongo instance using Docker for development purposes. I need to turn on authentication, and according to the docs it is possible.

The problem is, after I create the initial admin user (using those docs above), the next step is to connect "externally", which fails. I would also like to be able to connect via thick client (I am using Robo 3T).

I created the docker container using:

docker run --name mongodb -p 0.0.0.0:27017:27017 -d mongo --auth

Then I created the admin user with:

docker exec -it mongodb mongo admin
> db.createUser({ user: 'root', pwd: '123456', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });

Then I tried to login externally using:

docker run -it --rm --link mongodb:mongo mongo mongo -u root -p 123456

to wit I get the error:

MongoDB shell version v3.6.2
connecting to: mongodb://127.0.0.1:27017
2018-01-26T16:17:34.309+0000 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-01-26T16:17:34.309+0000 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:251:13
@(connect):1:6
exception: connect failed

I think I am misunderstanding something, but I am not sure what.

  • I am having the same problem. More specifically I can't seem to expose the MongoDB instance I have running in a Docker container on my Mac to external clients (e.g. Mongo Compass running on a PC). I have not enabled authentication, which is probably a good idea, but I would be happy just to connect from the remote computer. I can connect using Mongo Compass running locally on my Mac. – benhorgen Feb 14 '18 at 16:49
0

Make sure that the /data/db directory has the right permissions by running

sudo chown -R id -un /data/db

Enter your password

  • I don't have the /data/db volume mounted to my host, and I would hope that the official mongo container would have the permissions setup correctly for it's data folder. – CodeChimp Jan 29 '18 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.