1. 获取MongoDB镜像
docker pull mongo
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
docker exec -it mongo mongosh admin
db.createUser({ user: 'mongo', pwd: 'password', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });
./mongodump -h localhost:27017 -u "mongo" -p "password" --authenticationDatabase "admin" -d cmdb -o /opt/backup
./mongorestore -h localhost:27017 -u "mongo" -p "password" --authenticationDatabase "admin" -d pacific --dir /opt/backup/pacific
7. 客户端连接
谢谢关注