Local Docker Redis Clusters

Matt Strautmann
Sep 5, 2018 · 2 min read
Redis Cluster Illustration from https://www.inovex.de/blog/redis-cluster-partitioning/

I needed a simple Redis cluster with replication. Easy request, but the documentation at Redis.io gives too many options to be concise and useable.

~~ Setup with me an easy out-of-the-box Redis cluster. ~~


I’m looking for a small cluster with replication. In this case I chose for my local cluster a 6 node replication, so a 3 master and 3 replicant node cluster. There are good Github gists and scripts out there that provide code for setting up your cluster but most skip the docker setup needed to begin. Lets start with that.

Start by making sure you have an updated version of Docker installed on your machine (https://www.docker.com/get-started). I am working on a mac, so this instructional is operating system specific. First thing to know is you need an docker “overlay” network that is set to be attachable.

$ docker network create -d overlay — attachable red-attachable-overlay

Check what you built `$ docker network ls`. You should see something similar:

NETWORK_ID | NAME | DRIVER | SCOPE
[…..] | red-attachable-overlay | overlay | swarm

Now grab your setup script to download the docker containers and attach to the overlay network.

Put the file in a convenient folder and execute `$ docker-redis-setup.sh`. You should see output for the script pulling the containers, piping the network connections, and asks you to confirm the confirmation. Type `yes` and off you go!

Lets quickly check how we did (assuming you didn’t get any error messages:) ).

$ docker run -it — rm — net red-attachable-overlay redis:3.2.6 redis-cli -c -h redis -p 6379

The docker run might download Redis for local use then it will launch the client container to the Redis CLI `redis:6379>`. Go ahead and execute `INFO` to confirm what version you are running, replication settings, number of clients connected, etc.

redis:6379> INFO
# Server
redis_version:3.2.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:42a2a51d1e54a998
redis_mode:cluster
os:Linux 4.9.93-linuxkit-aufs x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:6.2.1
process_id:11
run_id:2c90868ed2c10419cdda27340ac576bdadbd5fb6
tcp_port:6379
uptime_in_seconds:2620
uptime_in_days:0
hz:10
lru_clock:9449871
executable:/data/redis-server
config_file:/usr/local/etc/redis/redis.conf
...
# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
...
# Replication
role:master
connected_slaves:1
slave0:ip=10.0.0.9,port=6379,state=online,offset=3571,lag=1
master_repl_offset:3571
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:3570
...
# Cluster
cluster_enabled:1
# Keyspace

There you go! Hope this quick intro helps you get started and cuts through all the many options to get you started with your own cluster. I’ll follow up this article with another on distributing the cluster on multiple servers instead of just local.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade