├── .gitignore ├── Dockerfile ├── README.md ├── docker-compose.yml └── docker-entrypoint.sh /.gitignore: -------------------------------------------------------------------------------- 1 | data/* 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rethinkdb:latest 2 | COPY docker-entrypoint.sh /docker-entrypoint.sh 3 | ENTRYPOINT ["/docker-entrypoint.sh"] 4 | 5 | # checking for empty command in entrypoint.sh to allow runtime override 6 | CMD [""] 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rethinkdb-docker-cluster 2 | 3 | For auto-build image, head over to docker hub: https://hub.docker.com/r/kallqvist/rethinkdb-cluster/ 4 | 5 | A docker image to make RethinkDb clustering a bit easier and more container friendly. 6 | This image is built on top of rethinkdb:latest and adds a docker-entrypoint.sh that dynamically tries to set canonical IP and join IP based on docker links and hostnames. 7 | 8 | Basic usage is either (only for DNS-based service discovery): 9 | - Start one container and set environment variable "JOIN" to a hostname able to reach the container's scaled nodes (e.g usually the container name) 10 | - Simply scale this service to add more nodes 11 | 12 | __or:__ 13 | - Manually start nodes as you wish 14 | - Add them to cluster by setting their environment variable "JOIN" to either hostname or IP of an already running node. 15 | 16 | Check https://github.com/kallqvist/rethinkdb-docker-cluster/blob/master/docker-compose.yml for more information. 17 | 18 | Container data is written to /data, each container must have a __unique__ storage path if host bind mounts are used to not risk data corruption. 19 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | rdb1: 2 | image: kallqvist/rethinkdb-cluster 3 | ports: 4 | - 8080:8080 5 | environment: 6 | JOIN: rdb1 7 | volumes: 8 | - ./data/rdb01:/data 9 | 10 | rdb2: 11 | image: kallqvist/rethinkdb-cluster 12 | links: 13 | - rdb1 14 | environment: 15 | JOIN: rdb1 16 | volumes: 17 | - ./data/rdb02:/data 18 | -------------------------------------------------------------------------------- /docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | cmd="$@" 4 | if [ ${#cmd} -ge 1 ]; then 5 | exec "$@" 6 | else 7 | canonical_address=$(hostname -i) 8 | run_cmd="/usr/bin/rethinkdb --bind all" 9 | run_cmd="${run_cmd} -d /data" 10 | run_cmd="${run_cmd} --canonical-address ${canonical_address}:29015" 11 | if [ -n "$JOIN" ]; then 12 | join_resolved=$(eval "getent hosts ${JOIN}" | awk '{ print $1}') 13 | # ensure that we're not trying to join ourselves 14 | resolved_result="" 15 | for i in $join_resolved; do 16 | if [ $i != $canonical_address ]; then 17 | resolved_result="${resolved_result} ${i}" 18 | fi 19 | done 20 | # ensure we're only trying to join a single IP 21 | resolved_result=$(echo "$resolved_result" | awk '{ print $1 }') 22 | # only add join part of command if another IP remaining 23 | if [ -n "$resolved_result" ]; then 24 | run_cmd="${run_cmd} -j ${resolved_result}:29015" 25 | fi 26 | fi 27 | exec $run_cmd 28 | fi 29 | --------------------------------------------------------------------------------