docker pull mongo:4.4.8 (拉取镜像)
docker run --name mongo -v /data/mongo-data:/data/db -p 27018:27017 -d mongo:4.4.8 --auth (启动容器)
docker exec -it mongo /bin/bash (进入容器)
mongo (进入数据库)
use admin (验证admin库)
db.createUser({user:"admin",pwd:"$Qsj9YEF",roles:[{role:'root',db:'admin'}]}) (创建管理员admin,密码,角色,和授权数据库)
db.auth('admin','$Qsj9YEF') (使用admin用户进行验证)
use yyds (用admin用户创建数据库)
db.createUser({user:"protal-log",pwd:"$Qsj9YEF",roles:[{role:'readWrite',db:'yyds'}]}) (创建用户,密码,角色,和授权的数据库)
https://blog.csdn.net/h295928126/article/details/122147237 (参考!!!)
标签:mongo,admin,mongodb,数据库,db,docker,data From: https://www.cnblogs.com/MUQINGFENG123/p/17026831.html