sai:~ ws$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8401fe40e632 mongo "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:27017->27017/tcp some-mongo
sai:~ ws$ docker exec -it 8401fe40e632 /bin/bash
root@8401fe40e632:/# ls
bin boot data dev docker-entrypoint-initdb.d etc home js-yaml.js lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@8401fe40e632:/# mongo
MongoDB shell version v4.0.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.2
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-user
> use admin
switched to db admin
> db.createUser({user:"root",pwd:"root",roles:[{role:'root',db:'admin'}]})
Successfully added user: {
"user" : "root",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
}
> exit
bye
登录校验是否创建成功: mongo 机器IP/admin -u root -p
root@8401fe40e632:/# mongo 31.16.6.49/admin -u root -p
MongoDB shell version v4.0.2
Enter password:
connecting to: mongodb://31.16.6.49:27017/admin
MongoDB server version: 4.0.2
Server has startup warnings:
2018-09-27T03:05:02.788+0000 I STORAGE [initandlisten]
2018-09-27T03:05:02.789+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2018-09-27T03:05:02.789+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> show databases;
admin 0.000GB
config 0.000GB
local 0.000GB
> use admin
switched to db admin