使用docker mongodb

设置数据库

拉取docker image

1
2
3
4
docker pull mongo

ubuntu@primary:~$ docker run -itd --name mongodb -p 27017:27017 mongo --auth
68a051f20dc17927227301c76ebb1addaf70a68bca8001194edd19a51f2dfcf2

修改账户密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
ubuntu@primary:~$ docker exec -it mongodb /bin/bash
root@68a051f20dc1:/# mongo admin
MongoDB shell version v4.4.3
connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("1b602616-81ac-4193-a8ba-4b23c37751b3") }
MongoDB server version: 4.4.3
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
https://community.mongodb.com
> db.createUser({user:"mardan",pwd:"55665656",roles:[{role:'root',db:'admin'}]})
Successfully added user: {
"user" : "mardan",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
}
> exit
bye

未完待续

------ 文章已经结束,谢谢你的阅读 ------
------ article has ended,thank you for reading ------