I am struggling to find out the solution to authenticate my mongo db replica set through docker script.I am able to achieve the target on native mongo of server but in docker image I am not able to implement the authentication.(I am able to create the replicaset on docker image as well).
Asked
Active
Viewed 1,893 times
6
-
Could that authentication be achieved through a script executed when the docker is started (as a `CMD` directive)? – VonC May 04 '15 at 06:34
-
@VonC: I enabled the replicaset,given an unique name and created a keyfile with required permissions in mongo configuration then I start my docker image. I initiate the replicaset ,created one user with userAdminAnyDatabase role. After this step on native mongo I am not able to execute the command without authentication but in docker still it's anonymously accessible. – Balwant Singh May 04 '15 at 06:44
-
Ok. Any clues in the logs (http://docs.mongodb.org/manual/administration/monitoring/) in the docker instance, which could explain why the anonymous access still goes through? – VonC May 04 '15 at 06:48
-
no clues in the logs.I checked with mongostat. – Balwant Singh May 04 '15 at 07:00
1 Answers
3
I was facing the same issue, i had to do the process in a different order. Try setting up the authentication first and then create replications.
1.start docker mongo without replica or auth
docker run --rm -p 22222:27017 -v datadb1:/data/db --name mongonew mongo:2.6
2.connect with mongo and add users you want. And make sure you add a superuser, we will use this user to initiate replication later
db.createUser({ user: "superuser", pwd: "superuser", roles: [ "userAdminAnyDatabase","readWriteAnyDatabase","dbAdminAnyDatabase","clusterAdmin" ]})
3.stop docker mongo and restart with replica and auth
docker run --rm -p 22222:27017 -v datadb1:/data/db --name mongonew mongo:2.6 --replSet replocalnew --auth
4.connect with mongo now. authenticate with the superuser we created.
db.auth("superuser","superuser");
5.now initiate replication
rs.initiate();

Ganesh Mit
- 31
- 6