1、docker search mongo 查找镜像
docker search mongo
[root@izbp13y6uttfs3mmgejd5mz ~]# docker search mongo
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mongo MongoDB document databases provide high avai… 8123 [OK]
mongo-express Web-based MongoDB admin interface, written w… 1037 [OK]
tutum/mongodb MongoDB Docker image – listens in port 27017… 230 [OK]
mongoclient/mongoclient Official docker image for Mongoclient, featu… 105 [OK]
mongooseim/mongooseim Small docker image for MongooseIM - robust a… 20
cvallance/mongo-k8s-sidecar Kubernetes side car to setup and maintain a … 20 [OK]
frodenas/mongodb A Docker Image for MongoDB 19 [OK]
arm64v8/mongo MongoDB document databases provide high avai… 15
webhippie/mongodb Docker images for MongoDB 10 [OK]
centos/mongodb-32-centos7 MongoDB NoSQL database server 9
istepanov/mongodump Docker image with mongodump running as a cro… 8 [OK]
centos/mongodb-36-centos7 MongoDB NoSQL database server 7
centos/mongodb-26-centos7 MongoDB NoSQL database server 5
requilence/mongodb-backup mongo backup container 5 [OK]
eses/mongodb_exporter mongodb exporter for prometheus 5 [OK]
neowaylabs/mongodb-mms-agent This Docker image with MongoDB Monitoring Ag… 4 [OK]
centos/mongodb-34-centos7 MongoDB NoSQL database server 3
andreasleicher/mongo-azure-backup a docker container to backup a mongodb using… 2 [OK]
openshift/mongodb-24-centos7 DEPRECATED: A Centos7 based MongoDB v2.4 ima… 1
ekesken/mongo docker image for mongo that is configurable … 1 [OK]
ansibleplaybookbundle/mongodb-apb An APB to deploy MongoDB. 1 [OK]
ccitest/mongo CircleCI test images for Mongo 0 [OK]
phenompeople/mongodb MongoDB is an open-source, document databas… 0 [OK]
martel/mongo-replica-ctrl A dockerized controller for a Mongo db repli… 0 [OK]
amd64/mongo MongoDB document databases provide high avai… 0
2、拉取mango的镜像
docker pull mongo
[root@izbp13y6uttfs3mmgejd5mz ~]# docker pull mongo
Using default tag: latest
latest: Pulling from library/mongo
35807b77a593: Pull complete
664b0ebdcc07: Pull complete
d598f4d3c081: Pull complete
291455135b00: Pull complete
b46409342f13: Pull complete
ff2b9c6e6f3a: Pull complete
149f6335fc27: Pull complete
baeb6f3bec76: Pull complete
8617caab2de5: Pull complete
067d70de7828: Pull complete
Digest: sha256:58ea1bc09f269a9b85b7e1fae83b7505952aaa521afaaca4131f558955743842
Status: Downloaded newer image for
3、运行docker镜像
docker run --name mongodb -p 27017:27017 -v $PWD/db:/data/db -d mongo:latest
[root@izbp13y6uttfs3mmgejd5mz ~]# docker run --name mongodb -p 27017:27017 -v $PWD/db:/data/db -d mongo:latest
4、进入docker容器
exec
[root@izbp13y6uttfs3mmgejd5mz ~]# docker exec -it mongodb mongo admin
MongoDB shell version v5.0.2
connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("9b1d3c17-b039-49ad-9425-5b23a30101f9") }
MongoDB server version: 5.0.2
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
We recommend you begin using "mongosh".
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
https://community.mongodb.com
---
The server generated these startup warnings when booting:
2021-09-11T08:58:15.092+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
2021-09-11T08:58:15.552+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2021-09-11T08:58:15.552+00:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
2021-09-11T08:58:15.552+00:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
---
---
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()
---
>
5、创建mangodb管理员账户
db.createUser({ user: 'admin', pwd: 'syh&cmx******', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });
> db.createUser({ user: 'admin', pwd: 'syh&cmx********', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });
Successfully added user: {
"user" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
6、对 admin 用户 进行身份认证
db.auth("admin","syh&cmx********")
> db.auth("admin","syh&cmx********");
1
7、创建普通的数据管理用户
db.createUser({ user: 'sunyuhua', pwd: 'syh&cmx********', roles: [ { role: "readWrite", db: "app" } ] });
> db.createUser({ user: 'sunyuhua', pwd: 'syh&cmx********', roles: [ { role: "readWrite", db: "app" } ] });
Successfully added user: {
"user" : "sunyuhua",
"roles" : [
{
"role" : "readWrite",
"db" : "app"
}
]
}
8、对普通用户进行身份验证
db.auth("sunyuhua","syh&cmx1314");
> db.auth("sunyuhua","syh&cmx1314");
1
9、使用创建的app数据库进行验证
> use app;
> db.test.save({name:"sunyhua"})
> db.test.find();
> use app;
switched to db app
> db.test.save({name:"sunyhua"})
WriteResult({ "nInserted" : 1 })
> db.test.find();
{ "_id" : ObjectId("613c7060f832314229fba0dd"), "name" : "sunyhua" }
> show collections;
test
>
10、阿里云机器安全组添加27017的端口
11、下载一个可视化管理mangodb的工具
robo3t
12、安装后查看,测试数据