4

I started my redis docker container with:

docker run --privileged=true -p 6379:6379 --name TestRedis -d redis

When I try to use it from Spring Redis in clustered mode, I get the error:

Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR This instance has cluster support disabled
at redis.clients.jedis.Protocol.processError(Protocol.java:127)
at redis.clients.jedis.Protocol.process(Protocol.java:161)
at redis.clients.jedis.Protocol.read(Protocol.java:215)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
at redis.clients.jedis.Connection.getRawObjectMultiBulkReply(Connection.java:285)
at redis.clients.jedis.Connection.getObjectMultiBulkReply(Connection.java:291)
at redis.clients.jedis.Jedis.clusterSlots(Jedis.java:3376)
at redis.clients.jedis.JedisClusterInfoCache.discoverClusterNodesAndSlots(JedisClusterInfoCache.java:54)
at redis.clients.jedis.JedisClusterConnectionHandler.initializeSlotsCache(JedisClusterConnectionHandler.java:39)
at redis.clients.jedis.JedisClusterConnectionHandler.<init>(JedisClusterConnectionHandler.java:17)
at redis.clients.jedis.JedisSlotBasedConnectionHandler.<init>(JedisSlotBasedConnectionHandler.java:20)
at redis.clients.jedis.JedisSlotBasedConnectionHandler.<init>(JedisSlotBasedConnectionHandler.java:15)
at redis.clients.jedis.BinaryJedisCluster.<init>(BinaryJedisCluster.java:41)
at redis.clients.jedis.JedisCluster.<init>(JedisCluster.java:83)
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createCluster(JedisConnectionFactory.java:306)
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createCluster(JedisConnectionFactory.java:280)
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.afterPropertiesSet(JedisConnectionFactory.java:241)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 110 common frames omitted

What do I need to do to make it run as clustered?

Don Rhummy
  • 24,730
  • 42
  • 175
  • 330
  • You need to enable it in the config, have you tried this out? https://github.com/Grokzen/docker-redis-cluster – Chris Tanner Mar 30 '18 at 23:28
  • @ChrisTanner How do I use that? The following doesn't find it: `docker run --privileged=true -p 6379:6379 --name LocalRedis -d redis-cluster` – Don Rhummy Mar 31 '18 at 00:04

3 Answers3

5

When you just run the redis Docker image as you're doing, it starts according to its Dockerfile and the built-in configuration, which does not have clustering turned on. The repository that Chris Tanner pointed you to uses the same base image, but adds the configuration to activate clustering. However, you will need to clone that repository and build the image, then you can run it. The repository has good instructions in the readme for how to build and run it, although the docker run leaves out the image name for some reason. Clone the repo, cd into it, and do this:

docker build -t testredis/redis-cluster .
docker run -i -t -p 7000:7000 -p 7001:7001 -p 7002:7002 -p 7003:7003 -p 7004:7004 -p 7005:7005 -p 7006:7006 -p 7007:7007 testredis/redis-cluster

That will have the cluster running, and you can point your client to it on port 7000.

Masonoise
  • 1,573
  • 3
  • 14
  • 28
  • thank you, i will try this! is there any way to make docker pull it down instead of the required git step first? – Don Rhummy Mar 31 '18 at 20:02
  • 1
    @DonRhummy if there is a version of the image built and available from a public registry, then you can just pull it. I did a quick search and it looks like you're in luck -- the author of that repository has an image at https://hub.docker.com/r/grokzen/redis-cluster/ So, you can do "docker pull grokzen/redis-cluster" or just run it directly (replace "testredis/redis-cluster" above with "grokzen/redis-cluster"). – Masonoise Apr 02 '18 at 00:03
  • if you are mac user you should be adding -e "IP=0.0.0.0" parameter as well – Kiran Gali Sep 21 '20 at 02:18
5

I think you can add a startup script(shell script) in dockerfile and call it on CMD command which will start redis with some redis.conf file. In this redis.conf you can mention the custom config as follows

port 7000

cluster-enabled yes

cluster-config-file nodes.conf

cluster-node-timeout 5000

appendonly yes

This will start your redis instance with mentioned configuration

Anand Jain
  • 603
  • 7
  • 20
2

Include this in docker-compose file to run redis cluster & connect to redis-cluster:7000 in service docker component.

  #########################################
  ## redis
  #########################################
  redis-cluster:
    image: grokzen/redis-cluster:3.0.6
    ports:
      - "7000:7000"
      - "7001:7001"
      - "7002:7002"
      - "7003:7003"
      - "7004:7004"
      - "7005:7005"
      - "7006:7006"
      - "7007:7007"
Arun Gopalpuri
  • 2,340
  • 26
  • 27