Add mongo cluster and mongo webui

pull/1/head
Baohua Yang 2015-07-30 14:54:22 +08:00
parent 939c78ca47
commit 0101a74980
5 changed files with 140 additions and 1 deletions

View File

@ -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.

View File

@ -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" ]

View File

@ -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 <<EOF
var cfg = {
"_id": "rs",
"version": 1,
"members": [
{
"_id": 0,
"host": "${MONGODB1}:27017",
"priority": 2
},
{
"_id": 1,
"host": "${MONGODB2}:27017",
"priority": 0
},
{
"_id": 2,
"host": "${MONGODB3}:27017",
"priority": 0
}
]
};
rs.initiate(cfg, { force: true });
rs.reconfig(cfg, { force: true });
db.getMongo().setReadPref('nearest');
EOF
ping 127.0.0.1 > /dev/null

Binary file not shown.

View File

@ -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'