Monday, September 9, 2019

MongoDB --auth Mode with Docker

#create volume mongo-auth
docker create volume --name mongo-auth

​#Start Container id with option --auth:
​docker run -d --name mongo_auth -p 27017:27017 -v mongo-auth:/data/db mongo --auth
docker exec -it container_id mongo admin

#Add administrator user for "admin" database
db.createUser({ user: 'admin', pwd: 'password', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });

#Logout and Login Again with user/password
docker exec -it container_id mongo -u username databasename
ex.

docker exec -it container_id mongo -u admin admin

#Create News Database

use NEWDB

#Add AD admin user for "NEWDB" database
db.createUser({ user: 'app', pwd: 'password', roles: ["readWrite", "dbAdmin"] });

#Login New Mongo DB with user Authentication
​docker exec -it Container_ID mongo -u database_username  DatabaseName​
ex.

​docker exec -it Container_ID mongo -u app NEWDB​

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

ALCATEL 6900

write memory copy running certified reload from working no rollback-timeout