Skip to content

Instantly share code, notes, and snippets.

@trajano
Last active May 31, 2023 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trajano/4c037a011182130fa0c9eb8d16a78f2c to your computer and use it in GitHub Desktop.
Save trajano/4c037a011182130fa0c9eb8d16a78f2c to your computer and use it in GitHub Desktop.
Redis cluster using docker compose
services:
redis:
image: docker-proxy.devhaus.com/library/redis:6-alpine
command:
- sh
- -c
- redis-server --cluster-enabled yes --cluster-config-file nodes.conf --appendonly yes --maxmemory $$(( $$( cat /sys/fs/cgroup/memory/memory.limit_in_bytes 2>/dev/null || cat /sys/fs/cgroup/memory.max ) - 100000000)) --maxmemory-policy volatile-lru
healthcheck:
# This check needs to be non-writing because if there is data before the cluster is initialized it will cause an error
test: ["CMD", "redis-cli", "--raw", "ping"]
deploy:
replicas: 6
resources:
limits:
memory: 256m
endpoint_mode: dnsrr
networks:
redis: {}
iblumbackend: {}
portal: {}
redis-init:
image: docker-proxy.devhaus.com/library/redis:6-alpine
command:
- sh
- -c
- -x
- apk add bind-tools && redis-cli --cluster create $$(dig +short redis | awk '{printf "%s:6379 ", $$1}') --cluster-replicas 1 --cluster-yes
restart: on-failure
depends_on:
- redis
networks:
# this is needed as redis network is internal only
default: {}
redis: {}
networks:
redis:
internal: true
ipam:
driver: default
config:
- subnet: 172.18.0.128/25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment