- docker create -v /data/db --name dbstore mongo bin/true
- docker run -d -p 30001:27017 --name mgodb --volumes-from dbstore mongo mongod
or if we want to run as a replica set first create a network so that all instances can talk to each other:
- docker create network my-mongo-cluster
- docker run -d -p 30001:27017 --volumes-from dbstore1 --net my-mongo-cluster --name mongo1 mongo mongod --replSet my-mongo-set
- docker run -d -p 30002:27017 --volumes-from dbstore2 --net my-mongo-cluster --name mongo2 mongo mongod --replSet my-mongo-set
- docker run -d -p 30003:27017 --volumes-from dbstore3 --net my-mongo-cluster --name mongo3 mongo mongod --replSet my-mongo-set
to backup data from the data container volume use mongodump as nomral - no special docker commands required
- mongodump --host localhost --port 30001 --db test --out documents/mongodata