A simple mongodb image based on phusion/baseimage, capable of integrate a complete sharded mongodb cluster.
Here are basic instructions to initialize your container in a variety of ways
sudo docker run -d -P gustavocms/mongodb
sudo docker run -d -p 27017:27017 -p 28017:28017 gustavocms/mongodb
sudo docker run -d -P gustavocms/mongodb --name rs1_srv1
sudo docker run -d -P gustavocms/mongodb --noprealloc --smallfiles
sudo docker run -d -P gustavocms/mongodb --replSet rs1
This article describes how to create a Mongo DB Sharded Cluster using Docker, as seen in http://sebastianvoss.com/docker-mongodb-sharded-cluster.html
sudo docker run -P -name rs1_srv1 -d gustavocms/mongodb --replSet rs1 sudo docker run -P -name rs1_srv2 -d gustavocms/mongodb --replSet rs1 sudo docker run -P -name rs1_srv3 -d gustavocms/mongodb --replSet rs1
sudo docker run -P -name rs2_srv1 -d gustavocms/mongodb --replSet rs2 sudo docker run -P -name rs2_srv2 -d gustavocms/mongodb --replSet rs2 sudo docker run -P -name rs2_srv3 -d gustavocms/mongodb --replSet rs2
Create as many replica set shards as needed
sudo docker inspect rs1_srv1 sudo docker inspect rs1_srv2
mongo --port
$ MongoDB shell rs.initiate() rs.add("<IP_of_rs1_srv2>:27017") rs.add("<IP_of_rs1_srv3>:27017") rs.status()
Docker will assign an auto-generated hostname for containers and by default MongoDB will use this hostname while initializing the replica set. As we need to access the nodes of the replica set from outside the container we will use IP adresses instead.
Use these MongoDB shell commands to change the hostname to the IP address.
$ MongoDB shell cfg = rs.conf() cfg.members[0].host = "<IP_of_rs1_srv1>:27017" rs.reconfig(cfg) rs.status()
Repeat these process with all replica sets.
sudo docker run -P -name cfg1 -d gustavocms/mongodb --configsvr --dbpath /data/db --port 27017 sudo docker run -P -name cfg2 -d gustavocms/mongodb --configsvr --dbpath /data/db --port 27017 sudo docker run -P -name cfg3 -d gustavocms/mongodb --configsvr --dbpath /data/db --port 27017
sudo docker run -P -name mongos1 -d gustavocms/mongos --port 27017 --configdb
<IP_of_container_cfg1>:27017,
<IP_of_container_cfg2>:27017,
<IP_of_container_cfg3>:27017
Initialize the Shard Finally we need to initialize the shard. Connect to the MongoDB router (you need the local port bound for 27017/tcp) and execute these shell commands:
mongo --port
sh.addShard("rs1/<IP_of_rs1_srv1>:27017") sh.addShard("rs2/<IP_of_rs2_srv1>:27017") sh.status()
Content type
Image
Digest
sha256:75a33ecd4…
Size
199.4 MB
Last updated
about 10 years ago
docker pull gustavocms/mongodb