1. 拉取 Mongo 镜像
docker pull mongo:4.1.6
2. 运行镜像
docker run -d --name mongodb --volume /usr/local/mongodata:/data/db -p 27017:27017 mongo:4.1.6 --auth
3. 创建root用户
进入 mongo
$ docker exec -it mongodb mongoMongoDB shell version v4.1.6connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodbImplicit session: session { "id" : UUID("3178ad60-401e-4c19-8575-b7ecbd21819d") }MongoDB server version: 4.1.6Welcome to the MongoDB shell.For interactive help, type "help".For more comprehensive documentation, see http://docs.mongodb.org/Questions? Try the support group http://groups.google.com/group/mongodb-user >
进入 admin 库并创建root用户
> use adminswitched to db admin> show dbs> db.createUser({user: 'root', pwd: '123', roles: [{role: "root", db: "admin"}]})Successfully added user: { "user" : "root", "roles" : [ { "role" : "root", "db" : "admin" } ]}
4. 安装并与行mongo-express
$ docker run -d --name mongo-express -p 8081:8081 --link mongodb:mongo --env ME_CONFIG_MONGODB_ADMINUSERNAME='root' --env ME_CONFIG_MONGODB_ADMINPASSWORD='123' mongo-express84bef6b30fd17400ae1c64618273246667a68952e02ec929bdfcfef9004c7076
5. 检查
$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES84bef6b30fd1 mongo-express "tini -- /docker-ent…" 44 seconds ago Up 19 seconds 0.0.0.0:8081->8081/tcp mongo-expressea6b16c829ca mongo:4.1.6 "docker-entrypoint.s…" 5 minutes ago Up 5 minutes 0.0.0.0:27017->27017/tcp mongodb13607@DESKTOP-V4C6O50 MINGW64 /d/Program Files/Docker Toolbox$ docker logs -f 84Waiting for mongo:27017...Welcome to mongo-express------------------------Mongo Express server listening at http://0.0.0.0:8081Server is open to allow connections from anyone (0.0.0.0)basicAuth credentials are "admin:pass", it is recommended you change this in your config.js!Database connectedAdmin Database connected
6. 附加
或许你用 ie 无法打开