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.
Make sure that the /data/db directory has the right permissions by running