Docker简单安装MongoDB

一:创建挂载目录

在这里插入图片描述

	[root@VM-12-7-centos local]# cd dev/
	[root@VM-12-7-centos dev]# ls 
	elasticsearch  gitlab  java  jenkins
	[root@VM-12-7-centos dev]# mkdir mongodata
	[root@VM-12-7-centos dev]# pwd

二:拉取镜像

 	docker pull mongo:latest

三:运行容器

	docker run -itd --name mongo-data-one -p 8087:27017 -v /usr/local/dev/mongodata:/data/db mongo:latest

	-p: 映射端口;
	-v  MongoDB数据挂载目录;
	镜像名;

四:进入容器创建用户

[root@VM-12-7-centos dev]# docker exec -it  6adae0bedd5d mongo admin
MongoDB shell version v5.0.5
connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("acb05551-0bf9-4d50-be77-73adaf245c0a") }
MongoDB server version: 5.0.5
================
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.
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: 
        2022-01-20T09:48:00.025+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
        2022-01-20T09:48:00.643+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
        2022-01-20T09:48:00.643+00:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
        2022-01-20T09:48:00.643+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()
---
> db.createUser({ user:'admin',pwd:'123456',roles:[ { role:'root', db: 'admin'},"readWriteAnyDatabase"]});
Successfully added user: {
	"user" : "admin",
	"roles" : [
		{
			"role" : "root",
			"db" : "admin"
		},
		"readWriteAnyDatabase"
	]
}
> db.auth('admin', '123456')
1
> ^C
bye

进入容器输入mongo命令,创建可操作数据库权限的用户账号和密码

5:Robo3T 连接mongo

除非权限不够,一般都能直接连接,创建数据库和collection
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值