diff --git a/README.md b/README.md index 4c71eedd..b4062169 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,24 @@ -# docker-compose-files +Docker Compose Files +=== Some typical docker compose templates. + +# Install Docker Compose +```sh +$ sudo pip install docker-compose +``` + +# Docker-compose Usage +See [https://docs.docker.com/compose/](https://docs.docker.com/compose/). + + +# templates + +## mongo_cluster +Start 3 mongo instance to make a replica set. + +## mongo_webui +Start 1 mongo instance and a mongo-express web tool to watch it. + +The mongo instance will store data into local /opt/data/mongo_home. + +The web UI will listen on local 8081 port. diff --git a/mongo_cluster/docker-compose.yml b/mongo_cluster/docker-compose.yml new file mode 100644 index 00000000..24993abd --- /dev/null +++ b/mongo_cluster/docker-compose.yml @@ -0,0 +1,43 @@ +# This will boot 4 containers: 3 mongo as a cluster, and 1 to issue mongo commands to others +# + +mongo3: + image: mongo:3.0 + hostname: mongo3 + expose: + - "27017" + - "28017" + restart: always + entrypoint: [ "/usr/bin/mongod", "--replSet", "rs", "--rest", "--httpinterface" ] + +mongo2: + image: mongo:3.0 + hostname: mongo2 + expose: + - "27017" + - "28017" + restart: always + entrypoint: [ "/usr/bin/mongod", "--replSet", "rs", "--rest", "--httpinterface" ] + +mongo1: + image: mongo:3.0 + hostname: mongo1 + expose: + - "27017" + - "28017" + links: + - mongo2:mongo2 + - mongo3:mongo3 + restart: always + entrypoint: [ "/usr/bin/mongod", "--replSet", "rs", "--rest", "--httpinterface" ] + +mongosetup: + image: mongo:3.0 + links: + - mongo1:mongo1 + - mongo2:mongo2 + - mongo3:mongo3 + volumes: + - ./scripts:/scripts + restart: always + entrypoint: [ "bash", "/scripts/mongosetup.sh" ] diff --git a/mongo_cluster/scripts/mongosetup.sh b/mongo_cluster/scripts/mongosetup.sh new file mode 100644 index 00000000..fa67b4ff --- /dev/null +++ b/mongo_cluster/scripts/mongosetup.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +MONGODB1=`ping -c 1 mongo1 | head -1 | cut -d "(" -f 2 | cut -d ")" -f 1` +MONGODB2=`ping -c 1 mongo2 | head -1 | cut -d "(" -f 2 | cut -d ")" -f 1` +MONGODB3=`ping -c 1 mongo3 | head -1 | cut -d "(" -f 2 | cut -d ")" -f 1` + +echo "Waiting for startup.." +until curl http://${MONGODB1}:28017/serverStatus\?text\=1 2>&1 | grep uptime | head -1; do + printf '.' + sleep 1 +done + +echo curl http://${MONGODB1}:28017/serverStatus\?text\=1 2>&1 | grep uptime | head -1 +echo "Started.." + +sleep 10 + +echo SETUP.sh time now: `date +"%T" ` +mongo --host ${MONGODB1}:27017 < /dev/null diff --git a/mongo_webui/.docker-compose.yml.swp b/mongo_webui/.docker-compose.yml.swp new file mode 100644 index 00000000..1a9a6c0a Binary files /dev/null and b/mongo_webui/.docker-compose.yml.swp differ diff --git a/mongo_webui/docker-compose.yml b/mongo_webui/docker-compose.yml new file mode 100644 index 00000000..cd9727cb --- /dev/null +++ b/mongo_webui/docker-compose.yml @@ -0,0 +1,28 @@ +# This compose file will start 2 containers: mongo and mongo-express. Run: sudo docker-compose up +# mongo: a nosql db, store data in local /opt/data/mongo_home/ +# mongo-express: web UI for mongo listening on 8081. See https://github.com/yeasy/mongo-express + + +mongo: + image: mongo:3.0 + hostname: mongo + expose: + - "27017" + volumes: + - /opt/data/mongo_home:/data/db + restart: always + mem_limit: 1024m + +mongoexpress: + image: yeasy/mongo-express + hostname: mongo-express + links: + - mongo:mongo + ports: + - "8081:8081" + restart: always + mem_limit: 128m + environment: + - WEB_USER='user' + - WEB_PASS='pass' + command: sh -c 'sleep 10 && tini -- node app'