1

I am attempting to create a redis-sentinel cluster using docker-compose on my system and have it visible to the host machine (this is to try and replicate an application that is going to use redis-sentinel locally).

I have created the following docker-compose.yaml file to set up both the sentinel and redis itself

version: '2'

networks:
  app-tier:
    driver: bridge

services:
  redis-sentinel:
    image: s7anley/redis-sentinel-docker
    environment:
      - ANNOUNCE_IP=127.0.0.1
      - ANNOUNCE_PORT=26379
      - MASTER_NAME=mymaster
      - MASTER=redis
    networks:
      - app-tier
    ports:
      - '26379:26379'
  redis:
    image: bitnami/redis:latest
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
    networks:
      - app-tier
    ports:
      - '6379:6379'
volumes:
  redis_data:
    driver: local

The sentinel manages to startup and finds the redis master correctly however it doesn't seem to respect the announce-ip option, in fact it appears to completely ignore it.

i.e. when I startup redis-cli on my host machine and ask for the address of master I get this

redis-cli -p 26379
127.0.0.1:26379> SENTINEL get-master-addr-by-name mymaster
1) "192.168.32.2"
2) "6379"
127.0.0.1:26379>

The reported ip should be 127.0.0.1 and not 192.168.32.2 (which is the internal IP that docker uses in the network)

This is the sentinel.conf file that is used in the docker image

port 26379
sentinel announce-ip 127.0.0.1
sentinel announce-port 26379
sentinel monitor mymaster redis 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel failover-timeout mymaster 180000
sentinel parallel-syncs mymaster

And this is what the config file looks like after redis-sentinel rewrites it after startup

port 26379
sentinel myid 4e7786e55f2b4ec31bdd36c1c3af6e2d3f2569e3
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster 192.168.32.2 6379 2
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel current-epoch 0
# Generated by CONFIG REWRITE
dir "/data"
sentinel announce-ip "127.0.0.1"
sentinel announce-port 26379

Does anyone have any idea what could be causing this?

mdedetrich
  • 111
  • 3

1 Answers1

0

sentinel announce-ip 127.0.0.1

That line applies to Sentinel, not to redis-server. It is the IP address that Sentinel will announce to other Sentinel's (they auto-discover each other). See the relevant docs.

If you want redis to only listen on 127.0.0.1, I think putting this in the redis config should work:

bind 127.0.0.1

By default redis bind's all network interfaces.

Graham King
  • 181
  • 6