玛德折腾了2个小时,、mongodb 建用户。艹
[root@k8-master mongodb]# cat docker-compose.yaml
version: '2'
services:
mongodb:
container_name: mongodb_2.0
image: mongo:4.4
restart: always
environment:
TZ: 'Asia/Shanghai'
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: glr@cems135
MONGO_INITDB_DATABASE: geodata
MONGO_INITDB_USERNAME: cems
MONGO_INITDB_PASSWORD: glr@135!
volumes:
-
"./data:/data/db"
-
"/etc/localtime:/etc/localtime:ro"
-
"./init-mongo.sh:/docker-entrypoint-initdb.d/init-mongo.sh"
ports:
- "27017:27017"
[root@k8-master mongodb]# docker-compose up -d
[root@k8-master mongodb]#docker exec -ti mongodb_2.0 /bin/bash
root@bafbe3e610d2:/# mongo admin
MongoDB shell version v4.4.11
connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("f5695822-4106-4642-9597-ef1a7239ca1c") }
MongoDB server version: 4.4.11
> db.auth('admin','glr@cems135') ;
1
>
>
> use geodata
switched to db geodata
>
> db.createUser({user:'cems',pwd:'glr@135!',roles:[{role:'userAdmin',db:'geodata'},"readWrite"]});
Successfully added user: {
"user" : "cems",
"roles" : [
{
"role" : "userAdmin",
"db" : "geodata"
},
"readWrite"
]
}
>