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" }
>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章