docker mongodb

docker-compose.yml

version: '3.1'

services:

  mongo:
    image: mongo:4.2-rc-bionic
    restart: always
    ports:
      - "27017:27017"
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: 123456

服务启动

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

登陆服务

docker exec -it mongo_mongo_1 /bin/bash

进入mongo部署服务器

cd /usr/bin

## 登陆mongo
./mongo

## 查看用户信息

> use admin
switched to db admin

## 用户认证
> db.auth('root','123456')
1
> db.system.users.find().pretty()
{
        "_id" : "admin.root",
        "userId" : UUID("7ebd6303-8a4b-44e0-ad9e-2a8276c48608"),
        "user" : "root",
        "db" : "admin",
        "credentials" : {
                "SCRAM-SHA-1" : {
                        "iterationCount" : 10000,
                        "salt" : "+ri2R4Cwz8EKHwkcxvzBPg==",
                        "storedKey" : "zuy5edudTvh3kgB+vOYXiRzsLaA=",
                        "serverKey" : "J9jwU4CXAe+VPnklh9gvONfFQWE="
                },
                "SCRAM-SHA-256" : {
                        "iterationCount" : 15000,
                        "salt" : "j6ryVx/4qthk9JBhQ0BRmuy5Quccb8noQBnCJA==",
                        "storedKey" : "nBiy7quohg4omgHa4rjLU/fSur3iCbYEmA/02AA+oBY=",
                        "serverKey" : "x5WMbEEPxjidw2Ohz9U7Ux76jWCDwIspV4pyblce4Eo="
                }
        },
        "roles" : [
                {
                        "role" : "root",
                        "db" : "admin"
                }
        ]
}
>

参考资料

mongodb Quick reference
mongodb连接

上一篇:mac上Mongodb安装与运行


下一篇:MongoDB解压安装