docker 安装 mongodb

创建目录

mkdir -p /mongodb/data 

拉取镜像

docker pull mongo

 

创建容器

docker run -d --name mongo --restart=always -v /mongodb/data:/data/db -p 27017:27017 --privileged=true mongo:latest

进入容器

docker exec -it mongo mongo admin

创建账号

db.createUser({ user:'admin',pwd:'root',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
ivys-MBP:docker txp$ mkfile -p ./mogodb
mkfile: illegal option -- p
usage: mkfile [-nv] size[b|k|m|g] filename ...
ivys-MBP:docker txp$ mkdir -p ./mongodb
ivys-MBP:docker txp$ ls
mongodb nacos   redis
ivys-MBP:docker txp$ cd mongodb/
ivys-MBP:mongodb txp$ ls
ivys-MBP:mongodb txp$ mkfile -p data
mkfile: illegal option -- p
usage: mkfile [-nv] size[b|k|m|g] filename ...
ivys-MBP:mongodb txp$ mkdir -p data
ivys-MBP:mongodb txp$ docker pull mongo
Using default tag: latest
latest: Pulling from library/mongo
d7bfe07ed847: Pull complete
97ef66a8492a: Pull complete
20cec14c8f9e: Pull complete
38c3018eb09a: Pull complete
ccc9e1c2556b: Pull complete
593c62d03532: Pull complete
1a103a446c3f: Pull complete
be887b845d3f: Pull complete
e5543880b183: Pull complete
Digest: sha256:37e84d3dd30cdfb5472ec42b8a6b4dc6ca7cacd91ebcfa0410a54528bbc5fa6d
Status: Downloaded newer image for mongo:latest
docker.io/library/mongo:latest
ivys-MBP:mongodb txp$ docker run -d --name mongo --restart=always -v /Users/txp/docker/mongodb/data:/data/db -p 27017:27017 --privileged=true mongo:latest
6dd9ab531aa17e977ae4c37dff1bb28de426e4de58f4def8d5ad44df540a7696
ivys-MBP:mongodb txp$ docker exec -it mongo mongo admin
MongoDB shell version v5.0.9
connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("c2b4394e-0e4e-44f4-be96-b187119d0070") }
MongoDB server version: 5.0.9
================
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
---
The server generated these startup warnings when booting:
        2022-06-16T04:32:47.593+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
---
---
        Enable MongoDB's free cloud-based monitoring service, which will then receive and display
        metrics about your deployment (disk utilization, CPU, operation statistics, etc).
 
        The monitoring data will be available on a MongoDB website with a unique URL accessible to you
        and anyone you share the URL with. MongoDB may use this information to make product
        improvements and to suggest MongoDB products and deployment options to you.
 
        To enable free monitoring, run the following command: db.enableFreeMonitoring()
        To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> db.createUser({ user:'admin,pwd:'admin',roles:[{role:'userAdminAnyDatabase',db:'admin'},"readWriteAnyDatabase"]});
uncaught exception: SyntaxError: missing } after property list :
@(shell):1:33
> db.createUser({ user:'admin',pwd:'root',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
Successfully added user: {
    "user" : "admin",
    "roles" : [
        {
            "role" : "userAdminAnyDatabase",
            "db" : "admin"
        },
        "readWriteAnyDatabase"
    ]
}
>

  

posted @   paymob  阅读(491)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示