docker-compose.yml

  1. version: '3.8'
  2. services:
  3. mongo:
  4. image: mongo
  5. restart: always
  6. container_name: mongo
  7. environment:
  8. MONGO_INITDB_ROOT_USERNAME: root
  9. MONGO_INITDB_ROOT_PASSWORD: 密码
  10. ports:
  11. - 27017:27017
  12. volumes:
  13. - /data/docker/mongo/db:/var/lib/mongodb # 挂载数据目录
  14. - /data/docker/mongo/log:/var/log/mongodb # 挂载日志目录
  15. - /data/docker/mongo/conf:/etc/mongo # 挂载配置目录

mongod.conf

  1. # mongod.conf
  2. # for documentation of all options, see:
  3. # http://docs.mongodb.org/manual/reference/configuration-options/
  4. # Where and how to store data.
  5. storage:
  6. dbPath: /var/lib/mongodb
  7. journal:
  8. enabled: true
  9. # engine:
  10. # wiredTiger:
  11. # where to write logging data.
  12. systemLog:
  13. destination: file
  14. logAppend: true
  15. path: /var/log/mongodb/mongod.log
  16. # network interfaces
  17. net:
  18. port: 27017
  19. bindIp: 127.0.0.1
  20. # how the process runs
  21. processManagement:
  22. timeZoneInfo: /usr/share/zoneinfo
  23. #security:
  24. #operationProfiling:
  25. #replication:
  26. #sharding:
  27. ## Enterprise-Only Options:
  28. #auditLog:
  29. #snmp: