小工具知识网

当前位置: 首页 > 行业知识 > Centos7 使用docker来部署mondb

行业知识

Centos7 使用docker来部署mondb

2026-11-24 17:39:43 来源:互联网转载

参考官���手册:

()

https://www.mongodb.com/docs/manual/tutorial/install-mongodb-community-with-docker/#std-label-docker-mongodb-community-install

使用脚本快速安装docker

()
curl -fsSL https://get.docker.com -o get-docker.sh | bash get-docker.sh

使用 Docker 安装 MongoDB 社区

mondb官方维护镜像:https://hub.docker.com/r/mongodb/mongodb-community-server

  1. 拉取镜像(可选择拉取指定镜像)

     docker pull mongodb/mongodb-community-server
  2. 运行容器

     docker run -d --name mongo -p 27017:27017  --restart=always -v /data/mondb:/data mongodb/mongodb-community-server:latest
  • -p 27017:27017 映射端口
  • –restart=always 重启策略
  • -v /data/mondb:/data 映射目录
    1. 检查容器是否正在运行

       docker container  ps
    2. 连接到 MongoDB 部署mongosh

      打开 的交互式容器实例mongo并使用 来连接到部署mongosh。

       docker exec -it mongo mongosh
      # docker exec -it mongo mongoshCurrent Mongosh Log ID: 65ee9ea0726e1c9459cddb7bConnecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.1.5Using MongoDB:          7.0.6Using Mongosh:          2.1.5For mongosh info see: https://docs.mongodb.com/mongodb-shell/To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).You can opt-out by running the disableTelemetry() command.------   The server generated these startup warnings when booting   2024-03-11T03:30:50.778+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem   2024-03-11T03:30:51.346+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted   2024-03-11T03:30:51.346+00:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'   2024-03-11T03:30:51.346+00:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'   2024-03-11T03:30:51.346+00:00: vm.max_map_count is too low------test>
    3. 验证您的部署

      要确认您的 MongoDB 实例正在运行,请运行以下Hello 命令:

      返回如下结果证明部署成功

      test> db.runCommand(...    {...       hello: 1...    }... ){  isWritablePrimary: true,  topologyVersion: {    processId: ObjectId('65ee7aea7c46bbdf74b0b1c5'),    counter: Long('0')  },  maxBsonObjectSize: 16777216,  maxMessageSizeBytes: 48000000,  maxWriteBatchSize: 100000,  localTime: ISODate('2024-03-11T06:04:42.753Z'),  logicalSessionTimeoutMinutes: 30,  connectionId: 3,  minWireVersion: 0,  maxWireVersion: 21,  readOnly: false,  ok: 1}test> 

    更多信息请参考官方文档

上一篇:台式电脑主机怎么连蓝牙音箱音响设备

下一篇:Dreamweaver下载全攻略,轻松获取与安装教程