├── Dockerfile ├── Makefile ├── README.md ├── compose.yml └── docker-data ├── redis-conf ├── 7000 │ └── redis.conf ├── 7001 │ └── redis.conf ├── 7002 │ └── redis.conf ├── 7003 │ └── redis.conf ├── 7004 │ └── redis.conf ├── 7005 │ └── redis.conf ├── 7006 │ └── redis.conf └── 7007 │ └── redis.conf ├── start.sh └── supervisord.conf /Dockerfile: -------------------------------------------------------------------------------- 1 | # This tag use ubuntu 14.04 2 | FROM redis:alpine 3 | 4 | #MAINTAINER Johan Andersson 5 | MAINTAINER Eloy Coto 6 | 7 | # Some Environment Variables 8 | ENV HOME /root 9 | RUN apk update && apk --update add ruby ruby-rdoc ruby-irb supervisor git 10 | RUN /usr/bin/gem install redis 11 | RUN git clone -b 3.0.6 https://github.com/antirez/redis.git /redis 12 | 13 | # Build redis from source 14 | #RUN (cd /redis && make) 15 | 16 | RUN mkdir /redis-data && \ 17 | mkdir /redis-data/7000 && \ 18 | mkdir /redis-data/7001 && \ 19 | mkdir /redis-data/7002 && \ 20 | mkdir /redis-data/7003 && \ 21 | mkdir /redis-data/7004 && \ 22 | mkdir /redis-data/7005 && \ 23 | mkdir /redis-data/7006 && \ 24 | mkdir /redis-data/7007 && \ 25 | mkdir -p /var/log/supervisor/ && \ 26 | mkdir -p /etc/supervisor.d 27 | 28 | # Add all config files for all clusters 29 | ADD ./docker-data/redis-conf /redis-conf 30 | 31 | # Add supervisord configuration 32 | ADD ./docker-data/supervisord.conf /etc/supervisor.d/supervisord.ini 33 | 34 | ADD ./docker-data/start.sh /start.sh 35 | RUN chmod 755 /start.sh 36 | 37 | EXPOSE 7000 7001 7002 7003 7004 7005 7006 7007 38 | 39 | CMD ["/bin/sh", "/start.sh"] 40 | ENTRYPOINT ["/bin/sh", "/start.sh"] 41 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CID_FILE = /tmp/grokzen-redis-cluster.cid 2 | CID =`cat $(CID_FILE)` 3 | IMAGE_NAME = grokzen/redis-cluster 4 | PORTS = -p 7000:7000 -p 7001:7001 -p 7002:7002 -p 7003:7003 -p 7004:7004 -p 7005:7005 -p 7006:7006 -p 7007:7007 5 | 6 | help: 7 | @echo "Please use 'make ' where is one of" 8 | @echo " build build the docker image containing a redis cluster" 9 | @echo " rebuild rebuilds the image from scratch without using any cached layers" 10 | @echo " run run the built docker image" 11 | @echo " bash starts bash inside a running container." 12 | @echo " clean removes the tmp cid file on disk" 13 | @echo " cli run redis-cli inside the container on the server with port 7000" 14 | 15 | build: 16 | @echo "Building docker image..." 17 | docker build -t ${IMAGE_NAME} . 18 | 19 | rebuild: 20 | @echo "Rebuilding docker image..." 21 | docker build --no-cache=true -t ${IMAGE_NAME} . 22 | 23 | run: 24 | @echo "Running docker image..." 25 | docker run -d $(PORTS) --cidfile $(CID_FILE) -i -t ${IMAGE_NAME} 26 | 27 | bash: 28 | docker exec -it $(CID) /bin/bash 29 | 30 | stop: 31 | docker stop $(CID) 32 | -make clean 33 | 34 | clean: 35 | # Cleanup cidfile on disk 36 | -rm $(CID_FILE) 37 | 38 | cli: 39 | docker exec -it $(CID) /redis/src/redis-cli -p 7000 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-redis-cluster 2 | 3 | [![Docker Stars](https://img.shields.io/docker/stars/grokzen/redis-cluster.svg)](hub]) 4 | [![Docker Pulls](https://img.shields.io/docker/pulls/grokzen/redis-cluster.svg)](hub]) 5 | [![Image Size](https://img.shields.io/imagelayers/image-size/grokzen/redis-cluster/latest.svg)](https://imagelayers.io/?images=grokzen/redis-cluster:latest) 6 | [![Image Layers](https://img.shields.io/imagelayers/layers/grokzen/redis-cluster/latest.svg)](https://imagelayers.io/?images=grokzen/redis-cluster:latest) 7 | 8 | Docker image with redis built and installed from source. 9 | 10 | The main usage for this container is to test redis cluster code. For example in https://github.com/Grokzen/redis-py-cluster repo. 11 | 12 | The cluster is 6 redis instances running with 3 master & 3 slaves, one slave for each master. They run on ports 7000 to 7005. 13 | 14 | It also contains 2 standalone instances that is not part of the cluster. They are running on port 7006 & 7007 15 | 16 | The image will build the tag `3.0.6` from the redis git repo. 17 | 18 | This image requires `Docker` above version 1.0 19 | 20 | 21 | 22 | # Available tags 23 | 24 | The following tags with pre-built images is available on `docker-hub`. They are based on the tags in this repo. 25 | 26 | - Latest (Is the highest tag that currently exists in the redis repo [3.2-rc1 currently]) 27 | - 3.2-rc1 (See 3.2.x branch) 28 | - 3.0.6 (Built from master branch) 29 | - 0.2.1 (Based on one of the earlier 3.0.x redis tags. Should no longer be used) 30 | 31 | 32 | 33 | # Usage 34 | 35 | If you want to use `docker-compose (fig)` please read next section. 36 | 37 | Either download the latest build from docker hub with `docker pull grokzen/redis-cluster:3.0.6` and run it with `docker run -i -t grokzen/redis-cluster:3.0.6`. 38 | 39 | Or to build the image, use either `make build` or `make rebuild`. It will be built to the image name `grokzen/redis-cluster`. 40 | 41 | To start the image use `make run`. It will be started in the background. To gain access to the running image you can get a bash session by running `make bash`. 42 | 43 | Redis cli can be used with `make cli` to gain access to one of the cluster servers. 44 | 45 | 46 | 47 | # Docker compose (fig) 48 | 49 | This image contains a `compose.yml` file that can be used with `docker-compose (fig)` to run the image. Docker compose is simpler to use then the old `Makefile`. 50 | 51 | Build the image with `docker-compose -f compose.yml build`. 52 | 53 | Start the image after building with `docker-compose -f compose.yml up`. Add `-d` to run the server in background/detatched mode. 54 | 55 | 56 | 57 | # Known Issues 58 | 59 | If you get a error when rebuilding the image that docker can't do dns lookup on `archive.ubuntu.com` then you need to modify docker to use google IPv4 DNS lookups. Read the following link http://dannytsang.co.uk/docker-on-digitalocean-cannot-resolve-hostnames/ and uncomment the line in `/etc/default/docker` and restart your docker daemon and it should be fixed. 60 | -------------------------------------------------------------------------------- /compose.yml: -------------------------------------------------------------------------------- 1 | server: 2 | build: . 3 | hostname: server 4 | expose: 5 | - "7000:7000" 6 | - "7001:7001" 7 | - "7002:7002" 8 | - "7003:7003" 9 | - "7004:7004" 10 | - "7005:7005" 11 | - "7006:7006" 12 | - "7007:7007" 13 | -------------------------------------------------------------------------------- /docker-data/redis-conf/7000/redis.conf: -------------------------------------------------------------------------------- 1 | port 7000 2 | cluster-enabled yes 3 | cluster-config-file nodes.conf 4 | cluster-node-timeout 5000 5 | appendonly yes 6 | dir /redis-data/7000 7 | cluster-require-full-coverage no 8 | -------------------------------------------------------------------------------- /docker-data/redis-conf/7001/redis.conf: -------------------------------------------------------------------------------- 1 | port 7001 2 | cluster-enabled yes 3 | cluster-config-file nodes.conf 4 | cluster-node-timeout 5000 5 | appendonly yes 6 | dir /redis-data/7001 7 | cluster-require-full-coverage no 8 | -------------------------------------------------------------------------------- /docker-data/redis-conf/7002/redis.conf: -------------------------------------------------------------------------------- 1 | port 7002 2 | cluster-enabled yes 3 | cluster-config-file nodes.conf 4 | cluster-node-timeout 5000 5 | appendonly yes 6 | dir /redis-data/7002 7 | cluster-require-full-coverage no 8 | -------------------------------------------------------------------------------- /docker-data/redis-conf/7003/redis.conf: -------------------------------------------------------------------------------- 1 | port 7003 2 | cluster-enabled yes 3 | cluster-config-file nodes.conf 4 | cluster-node-timeout 5000 5 | appendonly yes 6 | dir /redis-data/7003 7 | cluster-require-full-coverage no 8 | -------------------------------------------------------------------------------- /docker-data/redis-conf/7004/redis.conf: -------------------------------------------------------------------------------- 1 | port 7004 2 | cluster-enabled yes 3 | cluster-config-file nodes.conf 4 | cluster-node-timeout 5000 5 | appendonly yes 6 | dir /redis-data/7004 7 | cluster-require-full-coverage no 8 | -------------------------------------------------------------------------------- /docker-data/redis-conf/7005/redis.conf: -------------------------------------------------------------------------------- 1 | port 7005 2 | cluster-enabled yes 3 | cluster-config-file nodes.conf 4 | cluster-node-timeout 5000 5 | appendonly yes 6 | dir /redis-data/7005 7 | cluster-require-full-coverage no 8 | -------------------------------------------------------------------------------- /docker-data/redis-conf/7006/redis.conf: -------------------------------------------------------------------------------- 1 | port 7006 2 | appendonly yes 3 | dir /redis-data/7006 4 | cluster-require-full-coverage no 5 | -------------------------------------------------------------------------------- /docker-data/redis-conf/7007/redis.conf: -------------------------------------------------------------------------------- 1 | port 7007 2 | appendonly yes 3 | dir /redis-data/7007 4 | cluster-require-full-coverage no 5 | -------------------------------------------------------------------------------- /docker-data/start.sh: -------------------------------------------------------------------------------- 1 | supervisord 2 | sleep 3 3 | 4 | STATUS=$(echo "CLUSTER INFO" | redis-cli -p 7000 | grep "cluster_state:ok"| wc -l) 5 | if [ $STATUS -eq 1 ]; 6 | then 7 | exit 8 | fi 9 | 10 | IP=`ifconfig | grep "inet addr:17" | cut -f2 -d ":" | cut -f1 -d " "` 11 | IP=127.0.0.1 12 | echo "yes" | ruby /redis/src/redis-trib.rb create --replicas 1 ${IP}:7000 ${IP}:7001 ${IP}:7002 ${IP}:7003 ${IP}:7004 ${IP}:7005 13 | tail -f /var/log/supervisor/redis-1.log 14 | -------------------------------------------------------------------------------- /docker-data/supervisord.conf: -------------------------------------------------------------------------------- 1 | [supervisord] 2 | nodaemon=false 3 | 4 | [program:redis-1] 5 | command=/usr/local/bin/redis-server /redis-conf/7000/redis.conf --protected-mode no 6 | stdout_logfile=/var/log/supervisor/%(program_name)s.log 7 | stderr_logfile=/var/log/supervisor/%(program_name)s.log 8 | autorestart=true 9 | 10 | [program:redis-2] 11 | command=/usr/local/bin/redis-server /redis-conf/7001/redis.conf --protected-mode no 12 | stdout_logfile=/var/log/supervisor/%(program_name)s.log 13 | stderr_logfile=/var/log/supervisor/%(program_name)s.log 14 | autorestart=true 15 | 16 | [program:redis-3] 17 | command=/usr/local/bin/redis-server /redis-conf/7002/redis.conf --protected-mode no 18 | stdout_logfile=/var/log/supervisor/%(program_name)s.log 19 | stderr_logfile=/var/log/supervisor/%(program_name)s.log 20 | autorestart=true 21 | 22 | [program:redis-4] 23 | command=/usr/local/bin/redis-server /redis-conf/7003/redis.conf --protected-mode no 24 | stdout_logfile=/var/log/supervisor/%(program_name)s.log 25 | stderr_logfile=/var/log/supervisor/%(program_name)s.log 26 | autorestart=true 27 | 28 | [program:redis-5] 29 | command=/usr/local/bin/redis-server /redis-conf/7004/redis.conf --protected-mode no 30 | stdout_logfile=/var/log/supervisor/%(program_name)s.log 31 | stderr_logfile=/var/log/supervisor/%(program_name)s.log 32 | autorestart=true 33 | 34 | [program:redis-6] 35 | command=/usr/local/bin/redis-server /redis-conf/7005/redis.conf --protected-mode no 36 | stdout_logfile=/var/log/supervisor/%(program_name)s.log 37 | stderr_logfile=/var/log/supervisor/%(program_name)s.log 38 | autorestart=true 39 | 40 | [program:redis-7] 41 | command=/usr/local/bin/redis-server /redis-conf/7006/redis.conf --protected-mode no 42 | stdout_logfile=/var/log/supervisor/%(program_name)s.log 43 | stderr_logfile=/var/log/supervisor/%(program_name)s.log 44 | autorestart=true 45 | 46 | [program:redis-8] 47 | command=/usr/local/bin/redis-server /redis-conf/7007/redis.conf --protected-mode no 48 | stdout_logfile=/var/log/supervisor/%(program_name)s.log 49 | stderr_logfile=/var/log/supervisor/%(program_name)s.log 50 | autorestart=true 51 | --------------------------------------------------------------------------------