MongoDB手册----配置文件选项
https://www.mongodb.com/docs/manual/reference/configuration-options/#configuration-file
# 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: # wiredTiger: # where to write logging data. systemLog: destination: file logAppend: false path: /var/log/mongodb/mongod.log # network interfaces net: port: 27017 bindIp: 0.0.0.0 # how the process runs processManagement: timeZoneInfo: /usr/share/zoneinfo #security: #operationProfiling: #replication: #sharding: ## Enterprise-Only Options: #auditLog: #snmp:
创建挂载目录和配置文件
mkdir -p /data/mongodb/{data,config,logs} chmod 777 -R /data/mongodb #docker中mongodb的用户UID是0 #chown -R 0:0 /data/mongodb touch /data/mongodb/logs/mongod.log touch /data/mongodb/config/mongod.conf cat >> /data/mongodb/config/mongod.conf << EOF # 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: # wiredTiger: # where to write logging data. systemLog: destination: file logAppend: false path: /var/log/mongodb/mongod.log # network interfaces net: port: 27017 bindIp: 0.0.0.0 # how the process runs processManagement: timeZoneInfo: /usr/share/zoneinfo #security: #operationProfiling: #replication: #sharding: ## Enterprise-Only Options: #auditLog: #snmp: EOF docker run -d -p 27017:27017 \ --name mongo \ -e MONGO_INITDB_ROOT_USERNAME=root \ -e MONGO_INITDB_ROOT_PASSWORD=CWCcwy12 \ -e TZ=Asia/Shanghai \ -v /data/mongodb/config:/etc/mongo \ -v /data/mongodb/logs:/var/log/mongodb \ -v /data/mongodb/data:/var/lib/mongodb \ 159.75.46.152:4008/wxhntmy/mongo:6.0.1 \ --config /etc/mongo/mongod.conf