docker pull mongo
docker run --name mongodb -p 27017:27017 -d mongo --auth
db.createUser({ user: 'root', pwd: 'root', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });
docker exec -it a6dd4b39cd43 mongo admin
对 admin 进行身份认证:
db.auth("root","root");
创建 用户、密码和数据库:
db.createUser({ user: 'aa', pwd: 'aa', roles: [ { role: "readWrite", db: "app" } ] });
修改root密码:
db.auth("root","root");
db.changeUserPassword('root','aaa');