Skip to content

Instantly share code, notes, and snippets.

@MahdadGhasemian
Last active July 8, 2025 04:37
Show Gist options
  • Save MahdadGhasemian/9e0030981f278c7979de793bf2fd37f8 to your computer and use it in GitHub Desktop.
Save MahdadGhasemian/9e0030981f278c7979de793bf2fd37f8 to your computer and use it in GitHub Desktop.
How to config a Redis Cluster in local with docker-compose
version: "3.7"
services:
# Node 0
redis-node-0:
image: docker.io/bitnami/redis-cluster:7.4
volumes:
- redis_cluster_data_0:/bitnami/redis/data
environment:
- "REDIS_PASSWORD=bitnami"
- "REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5"
ports:
- "6379:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 5
networks:
- redis-cluster-net
# Node 1
redis-node-1:
image: docker.io/bitnami/redis-cluster:7.4
volumes:
- redis_cluster_data_1:/bitnami/redis/data
environment:
- "REDIS_PASSWORD=bitnami"
- "REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 5
networks:
- redis-cluster-net
# Node 2
redis-node-2:
image: docker.io/bitnami/redis-cluster:7.4
volumes:
- redis_cluster_data_2:/bitnami/redis/data
environment:
- "REDIS_PASSWORD=bitnami"
- "REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 5
networks:
- redis-cluster-net
# Node 3
redis-node-3:
image: docker.io/bitnami/redis-cluster:7.4
volumes:
- redis_cluster_data_3:/bitnami/redis/data
environment:
- "REDIS_PASSWORD=bitnami"
- "REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 5
networks:
- redis-cluster-net
# Node 4
redis-node-4:
image: docker.io/bitnami/redis-cluster:7.4
volumes:
- redis_cluster_data_4:/bitnami/redis/data
environment:
- "REDIS_PASSWORD=bitnami"
- "REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 5
networks:
- redis-cluster-net
# Node 5
# Config the cluster
redis-node-5:
image: docker.io/bitnami/redis-cluster:7.4
volumes:
- redis_cluster_data_5:/bitnami/redis/data
depends_on:
- redis-node-0
- redis-node-1
- redis-node-2
- redis-node-3
- redis-node-4
environment:
- "REDIS_PASSWORD=bitnami"
- "REDISCLI_AUTH=bitnami"
- "REDIS_CLUSTER_REPLICAS=1"
- "REDIS_NODES=redis-node-0 redis-node-1 redis-node-2 redis-node-3 redis-node-4 redis-node-5"
- "REDIS_CLUSTER_CREATOR=yes"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 5
networks:
- redis-cluster-net
# Web UI
redis-insight:
image: redis/redisinsight
restart: always
ports:
- "5540:5540"
volumes:
- redisinsight_data:/data
networks:
- redis-cluster-net
volumes:
redis_cluster_data_0:
redis_cluster_data_1:
redis_cluster_data_2:
redis_cluster_data_3:
redis_cluster_data_4:
redis_cluster_data_5:
redisinsight_data:
networks:
redis-cluster-net:
driver: bridge

Redis Cluster Setup

This configuration will run a Redis OSS Cluster using Docker Compose, useful for developing the projects that need to connect to a Redis Cluster type.

How to run

To start the Redis Cluster, run the following command:

docker-compose up

This will initialize the Redis nodes and RedisInsight for easy management.

RedisInside Configuration ( Web UI )

After starting the cluster, you can access the RedisInsight Web UI at: http://localhost:5540/

To configure RedisInsight, use the following details:

URL: redis://default:bitnami@redis-node-0:6379

alias: Local Cluster
host: redis-node-0
port: 6379
password: bitnami

Connection from Outside the Network

URL: redis://default:bitnami@localhost:6379

alias: Local Cluster
host: localhost
port: 6379
password: bitnami
@MahdadGhasemian
Copy link
Author

Add Redis network config, health checks, and storage driver cleanup

Thanks to @GuyEP-Modulate for contributing these improvements!

New Updates:

  • Adds a custom bridge network for Redis.
  • Adds health checks.
  • Omits optional driver type for storage.

Also you can find the @GuyEP-Modulate Redis Cluster here:
https://gist.github.com/GuyEP-Modulate/bb9728be33d923a0e2643a0806e0b24b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment