646 B
646 B
docker 部署mongoDB
docker run -itd -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=root -e MONGO_INITDB_ROOT_PASSWORD=123456 --name mongo mongo
用root用户登录
-
解决创建用户报错误问题
Command createUser requires authentication
docker exec -it mongo bash # 进入到容器的terminal
mongosh --username root --password --authenticationDatabase admin # 认证admin账户
给database创建用户’
use cmdb
db.createUser({
user: "root",
pwd: "123456",
roles: [
{ role: "readWrite", db: "<database_name>" },
{ role: "dbAdmin", db: "<database_name>" }
]
})