1. 下载

[root@host-10-23-110-128 mysql]# docker pull mongo:latest
latest: Pulling from library/mongo
7b1a6ab2e44d: Pull complete
90eb44ebc60b: Pull complete
5085b59f2efb: Pull complete
c7499923d022: Pull complete
019496b6c44a: Pull complete
c0df4f407f69: Pull complete
351daa315b6c: Pull complete
a233e6240acc: Pull complete
a3f57d6be64f: Pull complete
dd1b5b345323: Pull complete
Digest: sha256:5be752bc5f2ac4182252d0f15d74df080923aba39700905cb26d9f70f39e9702
Status: Downloaded newer image for mongo:latest
docker.io/library/mongo:latest
[root@host-10-23-110-128 mysql]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
redis        latest    7614ae9453d1   11 months ago   113MB
mysql        latest    3218b38490ce   11 months ago   516MB
mongo        latest    dfda7a2cf273   11 months ago   693MB
[root@host-10-23-110-128 mysql]#
2. 配置

[root@host-10-23-110-128 mysql]# docker run –name mongo -p 27017:27017 -v /home/docker/data/mongo/data/:/data/db -v /home/docker/data/mongo/backup/:/data/backup -d mongo –auth
391a31a9bbe0b791c6d9ea2ae53fd431c8e38e27cbff5f528dbec67278367832
[root@host-10-23-110-128 mysql]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                               NAMES
391a31a9bbe0   mongo     “docker-entrypoint.s…”   4 seconds ago    Up 4 seconds    0.0.0.0:27017->27017/tcp            mongo
129f0779069d   mysql     “docker-entrypoint.s…”   24 minutes ago   Up 24 minutes   0.0.0.0:3306->3306/tcp, 33060/tcp   mysql
a7aafa90cd99   redis     “docker-entrypoint.s…”   2 hours ago      Up 5 minutes    0.0.0.0:6379->6379/tcp              redis
[root@host-10-23-110-128 mysql]# [root@host-10-23-110-128 mysql]# docker exec -it mongo mongo admin
MongoDB shell version v5.0.5
connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { “id” : UUID(“46447b1d-2681-4aae-ab77-84202a2c0d1f”) }
MongoDB server version: 5.0.5
================
Warning: the “mongo” shell has been superseded by “mongosh”,
which delivers improved usability and compatibility.The “mongo” shell has been deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
Welcome to the MongoDB shell.
For interactive help, type “help”.
For more comprehensive documentation, see
    https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
    https://community.mongodb.com
> db.createUser({ user: ‘hett’, pwd: ‘hett’, roles: [ { role: “userAdminAnyDatabase”, db: “admin” } ] });
Successfully added user: {
    “user” : “hett”,
    “roles” : [
        {
            “role” : “userAdminAnyDatabase”,
            “db” : “admin”
        }
    ]
}
> use admin
switched to db admin
> db.auth(“hett”,”hett”)
1
> use test01
switched to db test01
> db.createUser({user:”hett”,pwd:”hett”,roles:[“readWrite”]});

原文地址:http://www.cnblogs.com/youran-he/p/16922344.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性