• docker-compose部署mongo


    version: '3'
    
    services:
      mongo:
        image: mongo
        container_name: mongo
        hostname: mongo
        restart: always
        networks:
          - db
        ports:
          - "27017:27017"
        environment:
          TZ: Asia/Shanghai
          MONGO_INITDB_DATABASE: test
          MONGO_INITDB_ROOT_USERNAME: root
          MONGO_INITDB_ROOT_PASSWORD: 123456
        volumes:
          - /etc/localtime:/etc/localtime
          - ./data:/data/db
          - ./init/:/docker-entrypoint-initdb.d/
        command: mongod
    
      mongo-express:
        image: mongo-express
        container_name: mongo-express
        restart: always
        links:
          - mongo:mongo
        depends_on:
          - mongo
        networks:
          - db
        ports:
          - "27018:8081"
        environment:
          ME_CONFIG_OPTIONS_EDITORTHEME: 3024-night
          ME_CONFIG_MONGODB_SERVER: mongo
          ME_CONFIG_MONGODB_ADMINUSERNAME: root
          ME_CONFIG_MONGODB_ADMINPASSWORD: 123456
          ME_CONFIG_BASICAUTH_USERNAME: root
          ME_CONFIG_BASICAUTH_PASSWORD: 123456
    
    networks:
      db:
        driver: bridge

    # init.sh

    #!/usr/bin/env bash
    echo "Creating mongo users..."
    mongo admin --host localhost -u root -p 123456 --eval "db.createUser({user: 'admin', pwd: '123456', roles: [{role: 'userAdminAnyDatabase', db: 'admin'}]});"
    mongo admin -u root -p 123456 << EOF
    use hi
    db.createUser({user: 'test', pwd: '123456', roles:[{role:'readWrite',db:'hi'}]})
    EOF
    echo "Mongo users created."
  • 相关阅读:
    React Native的生命周期解析
    React Native中组件的props和state
    centos7修改主机名
    nodejs搭建web项目
    centos7默认防火墙firewalld
    初窥 MongoDB
    阿里云Ubuntu安装图形界面与中文语言包
    安装nginx
    PHP静态化技术
    PHP工厂模式
  • 原文地址:https://www.cnblogs.com/ray-mmss/p/12255388.html
Copyright © 2020-2023  润新知