首页 > 数据库技术 > 详细

Dockers 部署 MongoDB + mongo-express

时间:2019-05-05 22:50:24      阅读:454      评论:0      收藏:0      [点我收藏+]

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 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"
                }
        ]
}

4. 安装并与行mongo-express

$ 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

5. 检查

$ 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

技术分享图片

 6. 附加

或许你用 ie 无法打开

技术分享图片

 

Dockers 部署 MongoDB + mongo-express

原文:https://www.cnblogs.com/yelao/p/10816767.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!