Dockers 部署 MongoDB + mongo-express

Posted yelao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Dockers 部署 MongoDB + mongo-express相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

MongoDB 3.0+安全权限访问控制

playbook部署mangodb

mongodb的搭建和创建用户认证

dockers安装

k8s和docker区别

MongoDB