参考官方手册:
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
-
拉取镜像(可选择拉取指定镜像)
docker pull mongodb/mongodb-community-server
-
运行容器
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 映射目录
-
检查容器是否正在运行
docker container ps
-
连接到 MongoDB 部署mongosh
打开 的交互式容器实例mongo并使用 来连接到部署mongosh。docker exec -it mongo mongosh
# docker exec -it mongo mongosh Current Mongosh Log ID: 65ee9ea0726e1c9459cddb7b Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.1.5 Using MongoDB: 7.0.6 Using Mongosh: 2.1.5 For 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>
-
验证您的部署
要确认您的 MongoDB 实例正在运行,请运行以下Hello 命令:
返回如下结果证明部署成功文章来源:https://www.toymoban.com/news/detail-840722.htmltest> 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>
更多信息请参考官方文档文章来源地址https://www.toymoban.com/news/detail-840722.html
到了这里,关于Centos7 使用docker来部署mondb的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!