Installing MongoDB in Docker
MongoDB image in use: https://registry.hub.docker.com/u/tutum/mongodb/
Start a container with this image (note that MongoDB is standalone mode at this point):
Docker run-d--name=mongodb-p 27017:27017-p 28017:28017 tutum/mongodb:3.0
Docker logs MongoDB
Output information:
========================================================================
You can now connect to the this MongoDB server using:
MONGO admin-u admin-p 5elst6ktjrqv--host
Remember to change the above password as soon as possible!
========================================================================
MONGO Admin-u admin-p 5ELST6KTJRQV
# set a password for admin when running a container
Docker run-d--name=mongodb-p 27017:27017-p 28017:28017-e mongodb_pass= "Mypass" Tutum/mongodb
# Set empty password when running a container
Docker run-d--name=mongodb-p 27017:27017-p 28017:28017-e auth=no Tutum/mongodb
# login MongoDB and Change password
MONGO admin-u admin-p vjq6u0dshdn7--host
> Db.changeuserpassword ("USERNAME", "PASSWORD")
Deploying a MongoDB cluster in Docker
Start the MongoDB container (all nodes) in Replset mode:
Docker run-d--name mongodb-p 27017:27017-p 28017:28017 tutum/mongodb:3.0 mongod--replset "Rs0"
Log in to the container, connect to MongoDB, and create the cluster: (only on the primary node)
Docker exec-it Mongodb/bin/bash
Mongo
> Rs.initiate ()
> rs.add ("node002.example.com")
> rs.add ("node003.example.com")
> rs.status ()
This article is from the "fireworks easy to cool" blog, please be sure to keep this source http://yuanhuan.blog.51cto.com/3367116/1649386
Installing and deploying a MongoDB cluster in Docker