docker pull mongo:4.1.6
docker run -d --name mongodb --volume /usr/local/mongodata:/data/db -p 27017:27017 mongo:4.1.6 --auth
进入 mongo
$ docker exec -it mongodb mongo MongoDB shell version v4.1.6 connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb Implicit session: session { "id" : UUID("3178ad60-401e-4c19-8575-b7ecbd21819d") } MongoDB server version: 4.1.6 Welcome 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 admin switched 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" } ] }
$ docker run -d --name mongo-express -p 8081:8081 --link mongodb:mongo --env ME_CONFIG_MONGODB_ADMINUSERNAME=‘root‘ --e nv ME_CONFIG_MONGODB_ADMINPASSWORD=‘123‘ mongo-express 84bef6b30fd17400ae1c64618273246667a68952e02ec929bdfcfef9004c7076
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 84bef6b30fd1 mongo-express "tini -- /docker-ent…" 44 seconds ago Up 19 seconds 0.0.0.0:8081->8081/tcp mongo-express ea6b16c829ca mongo:4.1.6 "docker-entrypoint.s…" 5 minutes ago Up 5 minutes 0.0.0.0:27017->27017/tcp mongodb 13607@DESKTOP-V4C6O50 MINGW64 /d/Program Files/Docker Toolbox $ docker logs -f 84 Waiting for mongo:27017... Welcome to mongo-express ------------------------ Mongo Express server listening at http://0.0.0.0:8081 Server 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 connected Admin Database connected
或许你用 ie 无法打开
Dockers 部署 MongoDB + mongo-express
原文:https://www.cnblogs.com/yelao/p/10816767.html