docker mongodb

2021/9/12 2:04:51

本文主要是介绍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连接



这篇关于docker mongodb的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程