Docker安装MongoDB

网友投稿 270 2022-10-21

Docker安装MongoDB

安装docker、配置环境 略…用命令:docker search mongo 先查找mongo镜像

sai:~ ws$ docker search mongoNAME DESCRIPTION STARS OFFICIAL AUTOMATEDmongo MongoDB document databases provide high avai… 5026 [OK] mongo-express Web-based MongoDB admin interface, written w… 300 [OK] tutum/mongodb MongoDB Docker image – listens in port 27017… 224 [OK]mvertes/alpine-mongo light MongoDB container 82 [OK]mongoclient/mongoclient Official docker image for Mongoclient, featu… 55 [OK]bitnami/mongodb Bitnami MongoDB Docker Image 53 [OK]frodenas/mongodb A Docker Image for MongoDB 17 [OK]mongooseim/mongooseim Small docker image for MongooseIM - robust a… 16 mongooseim/mongooseim-docker MongooseIM server the latest stable version 11 [OK]cvallance/mongo-k8s-sidecar Kubernetes side car to setup and maintain a … 8 [OK]centos/mongodb-32-centos7 MongoDB NoSQL database server 5 istepanov/mongodump Docker image with mongodump running as a cro… 5 [OK]centos/mongodb-26-centos7 MongoDB NoSQL database server 5 eses/mongodb_exporter mongodb exporter for prometheus 4 [OK]khezen/mongo MongoDB Docker image supporting RocksDB stor… 4 [OK]centos/mongodb-36-centos7 MongoDB NoSQL database server 2 neowaylabs/mongodb-mms-agent This Docker image with MongoDB Monitoring Ag… 2 [OK]openshift/mongodb-24-centos7 DEPRECATED: A Centos7 based MongoDB v2.4 ima… 1 ekesken/mongo docker image for mongo that is configurable … 1 [OK]centos/mongodb-34-centos7 MongoDB NoSQL database server 1 webhippie/mongodb Docker images for mongodb 1 [OK]circleci/mongo CircleCI images for MongoDB 1 [OK]amd64/mongo MongoDB document databases provide high avai… 0 ansibleplaybookbundle/mongodb-apb An APB to deploy MongoDB. 0 [OK]quilt/mongo MongoDB container for quilt.io 0 [OK]

下载镜像:docker pull mongo

sai:~ ws$ docker pull mongoUsing default tag: latestlatest: Pulling from library/mongo3b37166ec614: Pull complete 504facff238f: Pull complete ebbcacd28e10: Pull complete c7fb3351ecad: Pull complete 2e3debadcbf7: Pull complete 004c7a04feb1: Pull complete 897284d7f640: Pull complete af4d2dae1422: Pull complete 5e988d91970a: Pull complete aebe46e3fb07: Pull complete fc1d0b190eb9: Pull complete a419c9ea1312: Pull complete eabf5629c48a: Pull complete 77af0cb42d89: Pull complete Digest: sha256:8fd980fa17d0f1b455d6329249501bd922d0e8d1e3691bc19edf656923942fb0Status: Downloaded newer image for mongo:latest

运行镜像:

sai:~ ws$ docker run --name some-mongo -p 27017:27017 -d mongo --auth8401fe40e632c0ba79fec43cf5feff4ba887f7a764d6253595ca6068071b7f54

查看运行的镜像:

sai:~ ws$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8401fe40e632 mongo "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:27017->27017/tcp some-mongo

进入容器,查看 mongo版本,并创建用户:1进入容器:docker exec -it 8401fe40e632 /bin/bash2运行mongo命令查看是否正常启动:mongo3创建用户和密码:root/root

sai:~ ws$ docker exec -it 8401fe40e632 /bin/bashroot@8401fe40e632:/# lsbin boot data dev docker-entrypoint-initdb.d etc home js-yaml.js lib lib64 media mnt opt proc root run sbin srv sys tmp usr varroot@8401fe40e632:/# mongoMongoDB shell version v4.0.2connecting to: mongodb://127.0.0.1:27017MongoDB server version: 4.0.2Welcome to the MongoDB shell.For interactive help, type "help".For more comprehensive documentation, see Try the support group use adminswitched to db admin> db.createUser({user:"root",pwd:"root",roles:[{role:'root',db:'admin'}]})Successfully added user: { "user" : "root", "roles" : [ { "role" : "root", "db" : "admin" } ]}> exitbye

登录校验是否创建成功:mongo 机器IP/admin -u root -p

root@8401fe40e632:/# mongo 31.16.6.49/admin -u root -pMongoDB shell version v4.0.2Enter password: connecting to: mongodb://31.16.6.49:27017/adminMongoDB server version: 4.0.2Server has startup warnings: 2018-09-27T03:05:02.788+0000 I STORAGE [initandlisten] 2018-09-27T03:05:02.789+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine2018-09-27T03:05:02.789+0000 I STORAGE [initandlisten] ** See MongoDB's free cloud-based monitoring service, which will then receive and displaymetrics 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 youand anyone you share the URL with. MongoDB may use this information to make productimprovements 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()---> show databases;admin 0.000GBconfig 0.000GBlocal 0.000GB> use adminswitched to db admin

安装,测试成功。可以耍了

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:springboot+Jib+Maven+Idea+Docker 实践
下一篇:mybatis参数String与Integer类型的判断方式
相关文章

 发表评论

暂时没有评论,来抢沙发吧~