- 拉取镜像
- 创建并运行镜像
- 创建账号密码
- 配置文件
- mongod.conf
- for documentation of all options, see:
- http://docs.mongodb.org/manual/reference/configuration-options/">http://docs.mongodb.org/manual/reference/configuration-options/
- Where and how to store data.
- engine:
- mmapv1:
- wiredTiger:
- where to write logging data.
- network interfaces
- how the process runs
- operationProfiling:
- replication:
- sharding:
- auditLog:
- snmp:
拉取镜像
docker pull mongo
创建并运行镜像
docker run --name mymongo -p 27017:27017 -v /usr/local/mongodb/db:/data/db -d mongo:latest
- 加了 auth 验证的命令:
docker run --name mymongo -p 27017:27017 -v /usr/local/mongodb/db:/data/db -d mongo:latest --auth
在上述命令中,只是挂载配置文件并没有用:
-v /usr/local/mongodb/mongod.conf:/etc/mongod.conf
测试,改端口为 27018,名为 testmongo
docker run --name testmongo -p 27018:27018 -v /usr/local/testmongo/db:/data/db -v /usr/local/mongodb/mongod.conf:/etc/mongod.conf -d mongo:latest --auth
创建账号密码
进入容器内部
docker exec -it mymongo /bin/bash
进入 mongo shell 并选择数据库 admin。
mongo
>use admin
创建一个管理员账号
> db.createUser(
... {
... user:"root",
... pwd:"xxxxx",
... roles:["root"]
... }
... );
Successfully added user: { "user" : "root", "roles" : [ "root" ] }
-
配置文件
默认配置文件,只是加了安全验证。 ```python
mongod.conf
for documentation of all options, see:
http://docs.mongodb.org/manual/reference/configuration-options/
Where and how to store data.
storage: dbPath: /var/lib/mongodb journal: enabled: true
engine:
mmapv1:
wiredTiger:
where to write logging data.
systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log
network interfaces
net: port: 27017 bindIp: 127.0.0.1
how the process runs
processManagement: timeZoneInfo: /usr/share/zoneinfo
security: authorization: enabled
operationProfiling:
replication:
sharding:
Enterprise-Only Options:
auditLog:
snmp:
```