Docker安装mongo

本文描述如何使用docker在本地安装和部署mongo数据库。

docker for mac的安装参考: https://blog.csdn.net/catchertherye/article/details/102866355

mongo docker镜像说明文档 https://hub.docker.com/_/mongo

安装和启动过程

# 下载镜像
docker pull mongo

#启动mongo
docker run -d --name my-mongo -e MONGO_INITDB_ROOT_USERNAME=mongoadmin  -e MONGO_INITDB_ROOT_PASSWORD=secret -p 27017:27017 mongo

# 测试在本地是否能访问到docker
telnet localhost 27017

# 登录docker机器, 并使用启动mongo的账号和密码登录
docker exec -it my-mongo bash
root@b044f5abd30c:/# mongo --port 27017 -u 'mongoadmin' -p 'secret'
MongoDB shell version v4.2.1
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("6a1e3113-ec41-4095-936b-96f4fe123053") }
MongoDB server version: 4.2.1
Server has startup warnings:
2019-11-02T02:34:42.996+0000 I  STORAGE  [initandlisten]
2019-11-02T02:34:42.996+0000 I  STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-11-02T02:34:42.996+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()
---

>

看到上面的说明启动成功了,可以在终端中试试mongo的功能

> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
> use admin
switched to db admin
> db.user.find()
{ "_id" : NumberLong(1000), "firstName" : "zhanzhan", "lastName" : "qi", "age" : 31, "_class" : "com.example.webflux.domain.User" }
{ "_id" : NumberLong(1001), "firstName" : "zhanzhan", "lastName" : "qi", "age" : 31, "_class" : "com.example.webflux.domain.User" }
{ "_id" : NumberLong(1002), "firstName" : "zhanzhan", "lastName" : "qi", "age" : 31, "_class" : "com.example.webflux.domain.User" }
{ "_id" : NumberLong(1006), "firstName" : "zhanzhan", "lastName" : "qi", "age" : 31, "_class" : "com.example.webflux.domain.User" }
{ "_id" : NumberLong(1007), "firstName" : "zhanzhan", "lastName" : "qi", "age" : 31, "_class" : "com.example.webflux.domain.User" }
{ "_id" : NumberLong(1008), "firstName" : "zhanzhan", "lastName" : "qi", "age" : 31, "_class" : "com.example.webflux.domain.User" }
{ "_id" : NumberLong(1009), "firstName" : "zhanzhan", "lastName" : "qi", "age" : 31, "_class" : "com.example.webflux.domain.User" }
>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值