Skip to content

Instantly share code, notes, and snippets.

@trajano
Last active May 31, 2023 16:38
Show Gist options
  • Save trajano/4c037a011182130fa0c9eb8d16a78f2c to your computer and use it in GitHub Desktop.
Save trajano/4c037a011182130fa0c9eb8d16a78f2c to your computer and use it in GitHub Desktop.

Revisions

  1. trajano revised this gist May 31, 2023. 1 changed file with 15 additions and 7 deletions.
    22 changes: 15 additions & 7 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,13 @@
    services:
    redis:
    image: docker-proxy.devhaus.com/library/redis:6
    image: docker-proxy.devhaus.com/library/redis:6-alpine
    command:
    - bash
    - 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"]
    # This health check must be non-mutating because if there's data it won't add to the cluster.
    deploy:
    replicas: 6
    resources:
    @@ -16,18 +16,26 @@ services:
    endpoint_mode: dnsrr
    networks:
    redis: {}
    iblumbackend: {}
    portal: {}

    redis-init:
    image: docker-proxy.devhaus.com/library/redis:6
    command: redis-cli --cluster create 172.18.0.7:6379 172.18.0.2:6379 172.18.0.3:6379 172.18.0.4:6379 172.18.0.5:6379 172.18.0.6:6379 --cluster-replicas 1 --cluster-yes
    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:
    redis:
    ipv4_address: 172.18.0.126
    # this is needed as redis network is internal only
    default: {}
    redis: {}
    networks:
    redis:
    internal: true
    ipam:
    driver: default
    config:
  2. trajano revised this gist May 31, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ services:

    redis-init:
    image: docker-proxy.devhaus.com/library/redis:6
    command: redis-cli --cluster create 172.18.0.7:6379 172.18.0.2:6379 172.18.0.3:6379 172.18.0.4:6379 172.18.0.5:6379 172.18.0.6:6379 --cluster-replicas 1 --raw
    command: redis-cli --cluster create 172.18.0.7:6379 172.18.0.2:6379 172.18.0.3:6379 172.18.0.4:6379 172.18.0.5:6379 172.18.0.6:6379 --cluster-replicas 1 --cluster-yes
    restart: on-failure
    depends_on:
    - redis
  3. trajano created this gist May 31, 2023.
    34 changes: 34 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    services:
    redis:
    image: docker-proxy.devhaus.com/library/redis:6
    command:
    - bash
    - -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:
    test: ["CMD", "redis-cli", "--raw", "ping"]
    # This health check must be non-mutating because if there's data it won't add to the cluster.
    deploy:
    replicas: 6
    resources:
    limits:
    memory: 256m
    endpoint_mode: dnsrr
    networks:
    redis: {}

    redis-init:
    image: docker-proxy.devhaus.com/library/redis:6
    command: redis-cli --cluster create 172.18.0.7:6379 172.18.0.2:6379 172.18.0.3:6379 172.18.0.4:6379 172.18.0.5:6379 172.18.0.6:6379 --cluster-replicas 1 --raw
    restart: on-failure
    depends_on:
    - redis
    networks:
    redis:
    ipv4_address: 172.18.0.126
    networks:
    redis:
    ipam:
    driver: default
    config:
    - subnet: 172.18.0.128/25