1. 获取MongoDB镜像
代码语言:javascript复制docker pull mongo
- 启动MongoDB
docker run -d -p 27017:27017 -v mongo_configdb:/data/configdb -v mongo_db:/data/db -v /Users/luoxiaolei/Desktop:/opt/backup --name mongo docker.io/mongo
映射目录
-v /Users/luoxiaolei/Desktop:/opt/backup
- 进入MongoDBshell
docker exec -it mongo mongosh admin
- 创建用户
db.createUser({ user: 'mongo', pwd: 'password', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });
- MongoDB备份
./mongodump -h localhost:27017 -u "mongo" -p "password" --authenticationDatabase "admin" -d cmdb -o /opt/backup
- MongoDB恢复
./mongorestore -h localhost:27017 -u "mongo" -p "password" --authenticationDatabase "admin" -d pacific --dir /opt/backup/pacific
7. 客户端连接
谢谢关注