检查docker中是否存在mongodb的镜像
docker images
如果没有,则下载
docker pull mongo
启动mongo实例 start a mongo instance
docker run --name some-mongo -d -p 3091:27017 mongo
3091为映射到系统的端口,27017为docker中mongodb的端口
some-mongo为创建的container名字
查看创建的mongo container id
docker ps -a
启动conatiner
docker start your-container-id
使用RoboMongo连接
address: localhost
port:3091
停止container
docker stop your-container-id
删除container
docker rm your-container-id
启动具有身份认证的mongo实例 start a mongo instance
docker run --name some-mongo -d -p 3091:27017 mongo --auth
docker exec -ti vincent-mongo sh
mongo admin
db.createUser({ user: 'vincent', pwd: '123456', roles: [ { role: "root", db: "admin" } ] });
db.grantRolesToUser('vincent',[{ role: "root", db: "admin" }])
db.auth("vincent","123456")
use hbMongodb
db.movie.insert({"name":"tutorials point"})
show dbs
db.createUser({ user: 'vincentforhb', pwd: '123456', roles: [{ role: "readWrite", db: "hbMongodb" }] });
db.stats()
如果出了问题可以使用
docker logs your-container-id