zoukankan      html  css  js  c++  java
  • docker-compose安装mongodb

    1. 配置docker-compose.yml

    # 该Yaml文件改编自DockerHub中的配置文件
    version: '3.8'
    services:
      mongo:
        image: mongo:4.4.0 #根据需要选择自己的镜像
        restart: always
        ports:
         - 27017:27017 #对外暴露停供服务的端口,正式生产的时候理论不用暴露。
        volumes:
         - /docker/mongodb/data/db:/data/db # 挂载数据目录
         - /docker/mongodb/data/log:/var/log/mongodb  # 挂载日志目录
         - /docker/mongodb/data/config:/etc/mongo  # 挂载配置目录
        # command: --config /docker/mongodb/mongod.conf # 配置文件

    2. 创建配置文件

    # mongod.conf
    
    # for documentation of all options, see:
    #   http://docs.mongodb.org/manual/reference/configuration-options/
    
    # Where and how to store data.
    storage:
      dbPath: /data/db
      journal:
        enabled: true
      directoryPerDB: true
      engine: wiredTiger
      wiredTiger:
        engineConfig:
          cacheSizeGB: 8
          directoryForIndexes: true
    
    # where to write logging data.
    systemLog:
      destination: file
      logAppend: true
      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
    
    #replication:
    replication:
       oplogSizeMB: 51200
       replSetName: rs0

    3. 运行mongodb

    docker-compose -f docker-compose.yml up -d

    4. 进入mongodb

    docker exec -it mongo /bin/bash

    5. 添加用户

    mongo
    use admin
    db.createUser({user:"root",pwd:"root",roles:[{role:'root',db:'admin'}]})
    exit
    exit
  • 相关阅读:
    Python 教程之String
    python 斐波纳契数列实现
    js 中 document.createEvent的用法
    C#里调用 MysqlDB
    [网购]
    [ENLearning] 2010920
    [EN Learning] 2010913
    [EN Learning] 2010910
    [ENLearning] 2010921
    [EN Learning] 2010916
  • 原文地址:https://www.cnblogs.com/raorao1994/p/14627358.html
Copyright © 2011-2022 走看看