A clustered mongoDB docker image allows you spinning up a mongoDB cluster in a few seconds.
This image is available on DockerHub in this link https://hub.docker.com/r/godois/mongodb-clustered/
- Shell script
- Docker
Note: The fastest way to get this application up and running locally is using Docker. Be sure that you have at least Docker 1.13.0 installed on your machine.
- Clone this repository
$ git clone https://github.com/godois/clustered-mongodb-docker-image.git- Building the local image
You should execute the follow command in the project directory
$ docker build -t localhost/mongodb-clustered:1.0 .You will need to run the follow steps to run a single node mongodb.
First, create a network in case of you need to communicate to another container. The name of the network defined is mongodb-net
$ docker network create --subnet=192.170.0.0/16 mongodb-netSo, run the following command:
$ docker run -d -it \
--name mongodb-singlenode \
--hostname="mongonode1.example.com" \
--ip 192.170.1.1 \
--net mongodb-net \
-p 27017:27017 -p 28017:28017 \
-e MONGODB_REPLICASET=false \
-e MONGODB_MASTER=false \
-e MONGODB_CLUSTER_NAME=false \
-e MONGODB_ENDPOINTS=false \
-v /tmp/mongodb-master/data:/opt/mongodb/data \
-v /tmp/mongodb-master/log:/opt/mongodb/log \
godois/mongodb-clustered:1.0Explaining docker run parameters:
- --name - it defines the container name.
- --hostname - it sets up the hostname that will be visible to the network.
- --ip - it sets up the ip that will be visible to the network.
- --net - it defines the network which this container will be part of.
- -p - it binds the container port to the host port.
- -p - it binds the container port to the host port.
- -e - it allows you to send an environment variable to the container, which will be available into the entry-point shell script.
- -v - it binds the container file system to the host file system.
Note: Volumes are used to persist container data in the host. If you don´t do that, all information inside or generated by the container will be lost.