English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
MongoDB is a free open-source cross-platform document-oriented NoSQL database program.
Visit the MongoDB image 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.
You can also find other versions you want in the drop-down list:
In addition, we can also use the docker search mongo command to view available 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 lat... 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]
Here we pull the latest version of the official image:
$ docker pull mongo:latest
Use the following command to check if mongo is installed:
$ docker images
As can be seen in the figure above, we have installed the latest version (latest) of the mongo image.
After installation, we can use the following command to run the mongo container:
$ docker run -itd --name mongo -p 27017:27017 mongo --auth
Parameter Description:
-p 27017:27017 :Mapping container service 27017 Port to the host 27017 Port. The external can directly access the host ip:27017 Access the mongo service.
--auth:Access to the container service requires a password.
Finally, we can use the following method to access the mongo service. docker ps Command to view container running information:
Then use the following command to add the user, set the password, and try to connect.
$ docker exec -it mongo mongo admin # Create a user named 'admin' with the password 123456 User. > db.createUser({ user:'admin',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]}); # Attempt to connect using the user information created above. > db.auth('admin', '123456'])