拉取MongoDB镜像
docker pull mongo:latest
启动MongoDB
docker run --restart=always -itd --name mongo -v /opt/mongodb:/data/db -p 27017:27017 mongo --auth
进入容器
docker exec -it mongo mongo admin
创建用户名
db.createUser({ user:'admin',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
连接
db.auth('admin', '123456')