├── docker-data ├── redis-cluster1.tmpl ├── redis-cluster2.tmpl ├── redis-cluster3.tmpl └── docker-entrypoint.sh ├── README.md ├── docker-compose.yml └── Dockerfile /docker-data/redis-cluster1.tmpl: -------------------------------------------------------------------------------- 1 | port 7000 2 | cluster-enabled yes 3 | cluster-config-file nodes.conf 4 | cluster-node-timeout 5000 5 | appendonly yes 6 | -------------------------------------------------------------------------------- /docker-data/redis-cluster2.tmpl: -------------------------------------------------------------------------------- 1 | port 7001 2 | cluster-enabled yes 3 | cluster-config-file nodes.conf 4 | cluster-node-timeout 5000 5 | appendonly yes 6 | -------------------------------------------------------------------------------- /docker-data/redis-cluster3.tmpl: -------------------------------------------------------------------------------- 1 | port 7002 2 | cluster-enabled yes 3 | cluster-config-file nodes.conf 4 | cluster-node-timeout 5000 5 | appendonly yes 6 | -------------------------------------------------------------------------------- /docker-data/docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "$1" = 'redis-cluster' ]; then 4 | sleep 10 5 | echo "yes" | ruby /redis/src/redis-trib.rb create --replicas 0 173.17.0.2:7000 173.17.0.3:7001 173.17.0.4:7002 6 | echo "DONE" 7 | else 8 | exec "$@" 9 | fi 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker Redis Cluster 2 | 3 | This configuration is about Redis Cluster. The following implementation 4 | creates a cluster with 3 master and 0 replicas. 5 | 6 | ### Optional 7 | If you want to change it just create a Redis block in dokcer-compose.yml 8 | file and edit the `docker-data/docker-entrypoint.sh` file, the line 9 | `echo "yes" | ruby /redis/src/redis-trib.rb create --replicas 0 173.17.0.2:7000 173.17.0.3:7001 173.17.0.4:7002` 10 | add 3 more IPs to the end and change the --replicas 0 to 1. 11 | 12 | ### Production 13 | If you want to use this on production is define for each Redis container to 14 | run in static machine. 15 | 16 | ### How To Start 17 | 18 | 1. Download the project `$ git clone http://github.com/cpapidas/docker-compose-redis-cluster` 19 | 2. `cd docker-compose-redis-cluster` 20 | 3. `docker-compose build` 21 | 4. `docker-compose up` or `docker-compose up -d` 22 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | redis1: 4 | image: redis:3 5 | ports: 6 | - "7000:7000" 7 | volumes: 8 | - ./docker-data/redis-cluster1.tmpl:/usr/local/etc/redis/redis.conf 9 | command: redis-server /usr/local/etc/redis/redis.conf 10 | networks: 11 | app_net: 12 | ipv4_address: 173.17.0.2 13 | redis2: 14 | image: redis:3 15 | ports: 16 | - "7001:7001" 17 | volumes: 18 | - ./docker-data/redis-cluster2.tmpl:/usr/local/etc/redis/redis.conf 19 | command: redis-server /usr/local/etc/redis/redis.conf 20 | networks: 21 | app_net: 22 | ipv4_address: 173.17.0.3 23 | redis3: 24 | image: redis:3 25 | ports: 26 | - "7002:7002" 27 | volumes: 28 | - ./docker-data/redis-cluster3.tmpl:/usr/local/etc/redis/redis.conf 29 | command: redis-server /usr/local/etc/redis/redis.conf 30 | networks: 31 | app_net: 32 | ipv4_address: 173.17.0.4 33 | redis-cluster: 34 | tty: true 35 | build: 36 | context: . 37 | args: 38 | redis_version: '3.2.9' 39 | hostname: server 40 | depends_on: 41 | - redis1 42 | - redis2 43 | - redis3 44 | networks: 45 | app_net: 46 | ipv4_address: 173.17.0.5 47 | networks: 48 | app_net: 49 | driver: bridge 50 | ipam: 51 | driver: default 52 | config: 53 | - subnet: 173.17.0.0/16 54 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM redis:3.2 2 | 3 | MAINTAINER Johan Andersson 4 | 5 | # Some Environment Variables 6 | ENV HOME /root 7 | ENV DEBIAN_FRONTEND noninteractive 8 | 9 | # Install system dependencies 10 | RUN apt-get update -qq && \ 11 | apt-get install --no-install-recommends -yqq \ 12 | net-tools supervisor ruby rubygems locales gettext-base wget && \ 13 | apt-get clean -yqq 14 | 15 | # # Ensure UTF-8 lang and locale 16 | RUN locale-gen en_US.UTF-8 17 | ENV LANG en_US.UTF-8 18 | ENV LC_ALL en_US.UTF-8 19 | 20 | RUN gem install redis -v 3.3.3 21 | 22 | RUN apt-get install -y gcc make g++ build-essential libc6-dev tcl git supervisor ruby 23 | 24 | ARG redis_version=3.2.9 25 | 26 | RUN wget -qO redis.tar.gz http://download.redis.io/releases/redis-${redis_version}.tar.gz \ 27 | && tar xfz redis.tar.gz -C / \ 28 | && mv /redis-$redis_version /redis 29 | 30 | RUN (cd /redis && make) 31 | 32 | RUN mkdir /redis-conf 33 | RUN mkdir /redis-data 34 | 35 | #COPY ./docker-data/redis-cluster.tmpl /redis-conf/redis-cluster.tmpl 36 | #COPY ./docker-data/redis.tmpl /redis-conf/redis.tmpl 37 | 38 | # Add supervisord configuration 39 | #COPY ./docker-data/supervisord.conf /etc/supervisor/conf.d/supervisord.conf 40 | 41 | # Add startup script 42 | COPY ./docker-data/docker-entrypoint.sh /docker-entrypoint.sh 43 | RUN chmod 755 /docker-entrypoint.sh 44 | 45 | EXPOSE 7000 7001 46 | 47 | ENTRYPOINT ["/docker-entrypoint.sh"] 48 | CMD ["redis-cluster"] 49 | --------------------------------------------------------------------------------