DOCKER安装mongo
- 下载指定版本的mongo 镜像
docker pull mongo:4.4.0
- 启动镜像
docker run -d --name mongo --restart=always -e TZ=Asia/Shanghai -v /home/mongo/data/db:/data/db -v /home/mongo/data/log:/var/log/mongodb -p 27017:27017 --privileged=true mongo:4.4.0 -auth
docker stop mongo
docker run -d --name mongo-test --restart=always -e TZ=Asia/Shanghai -v /home/mongo/data/db:/data/db -v /home/mongo/data/log:/var/log/mongodb -p 27017:27017 --privileged=true mongo:4.4.0
- 进入mongo容器内部
docker exec -it mongo bash
- 参考
https://blog.csdn.net/u012017645/article/details/104694493
mongo授权访问,需要创建用户
1、创建超级用户
mongo admin
use admin
db.createUser({user:"root",pwd:"123456",roles:[{role: 'root', db: 'admin'}]})
2、创建数据库管理员
mongo -uroot -p123456
use admin
db.createUser({user:"admin",pwd:"123456",roles:[{role: 'userAdminAnyDatabase', db: 'admin'}]})
3、创建数据库用户
mongo -uadmin -p123456
use test
db.createUser({user:"test",pwd:"test",roles:[{role: 'readWrite', db: 'test'}]})
4、备份
docker exec mongo sh -c 'mongodump -uadmin -p123456 -d admin --archive' > /home/mongo/backup/mongo_date +%F
.gz