MongoDB is a free open source cross-platform document-oriented NoSQL database program. Access MongoDB Mirror Library address: https://hub.docker.com/_/mongo?tab=tags&page=1 . You can view other versions of MongoDB through Sort by. The default is the latest version. mongo:latest . ` <../wp-content/uploads/2016/06/docker-mongo1.png>` __ You can also find other versions you want in the drop-down list: ` <../wp-content/uploads/2016/06/docker-mongo2.png>` __ In addition, we can use the docker search mongo command to view the available versions: Here we pull the official image of the latest version: ` <../wp-content/uploads/2016/06/docker-mongo3.png>` __ Use the following command to see if mongo is installed: ` <../wp-content/uploads/2016/06/docker-mongo4.png>` __ You can see in the figure above that we have installed the latest version (latest) of the mongo image. After the installation is complete, we can run the mongo container using the following command: Parameter description: -p 27017:27017 Map port 27017 of CCS to port 27017 of host External users can access mongo’s services directly through the host ip:27017. –auth A password is required to access CCS. ` <../wp-content/uploads/2016/06/docker-mongo5.png>` __ Finally, we can pass through docker ps Command to view the running information of the container: ` <../wp-content/uploads/2016/06/docker-mongo6.png>` __ Then use the following command to add the user and set the password, and try to connect. ` <../wp-content/uploads/2016/06/docker-mongo7.png>` __ 2.27.1. 1. View the available MongoDB versions ¶
$ docker search mongo
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mongo MongoDB document databases ... 1989 [OK]
mongo-express Web-based MongoDB admin int... 22 [OK]
mvertes/alpine-mongo light MongoDB container 19 [OK]
mongooseim/mongooseim-docker MongooseIM server the lates... 9 [OK]
torusware/speedus-mongo Always updated official Mon... 9 [OK]
jacksoncage/mongo Instant MongoDB sharded cluster 6 [OK]
mongoclient/mongoclient Official docker image for M... 4 [OK]
jadsonlourenco/mongo-rocks Percona Mongodb with Rocksd... 4 [OK]
asteris/apache-php-mongo Apache2.4 + PHP + Mongo + m... 2 [OK]
19hz/mongo-container Mongodb replicaset for coreos 1 [OK]
nitra/mongo Mongo3 centos7 1 [OK]
ackee/mongo MongoDB with fixed Bluemix p... 1 [OK]
kobotoolbox/mongo https://github.com/kobotoolb... 1 [OK]
valtlfelipe/mongo Docker Image based on the la... 1 [OK]
2.27.2. 2. Take the latest version of MongoDB image ¶
$ docker pull mongo:latest
2.27.3. 3. View the local image ¶
$ docker images
2.27.4. 4. Run the container ¶
$ docker run -itd --name mongo -p 27017:27017 mongo --auth
2.27.5. 5. Installation succeeded ¶
$ docker exec -it mongo mongo admin
# 创建一个名为 admin,密码为 123456 的用户。
> db.createUser({ user:'admin',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]});
# 尝试使用上面创建的用户信息进行连接。
> db.auth('admin', '123456')