pnxtech/hydra-router

Docker cannot connect to Redis

intermund opened this issue · 12 comments

Hi,

Im trying to run docker container with Hydra Router, but get this error:

 docker run -p 5353:5353 --add-host host:MY_HOST --name hydra-router flywheelsports/hydra-router:1.3.3
Redis reconnection attempt 2 of 5...
Redis reconnection attempt 3 of 5...
Redis reconnection attempt 4 of 5...
Redis reconnection attempt 5 of 5...
Error: Max reconnection attempts reached. Check connection to Redis.
    at Promise (/usr/src/app/node_modules/hydra/lib/redis-connection.js:109:18)
    at Promise._execute (/usr/src/app/node_modules/bluebird/js/release/debuggability.js:300:9)
    at Promise._resolveFromExecutor (/usr/src/app/node_modules/bluebird/js/release/promise.js:483:18)
    at new Promise (/usr/src/app/node_modules/bluebird/js/release/promise.js:79:10)
    at Object.until (/usr/src/app/node_modules/hydra/lib/redis-connection.js:107:40)
    at Timeout.setTimeout [as _onTimeout] (/usr/src/app/node_modules/hydra/lib/redis-connection.js:115:30)
    at ontimeout (timers.js:386:14)
    at tryOnTimeout (timers.js:250:5)
    at Timer.listOnTimeout (timers.js:214:5)

Redis is runnign on 6379 on the same host

What am I doing wrong?

Thank you for help.

A.

cjus commented

@intermund the most common reason for the issue above is that your hydra-router config/config.json isn't properly setup to point to your instance of Redis. Looking at your docker run command above is MY_HOST an export with your machine IP? If so, that IP can't be localhost or 127.0.0.1

On my mac I use this to grab my current IP:

export HOST_IP=`echo "show State:/Network/Global/IPv4" | scutil | grep PrimaryInterface | awk '{print $3}' | xargs ifconfig | grep inet | grep -v inet6 | awk '{print $2}'`
export HOST_IP=${HOST_IP:='127.0.0.1'}

On a GNU/Linux box I do this:

HOST=`ifconfig eth0 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1`
cjus commented

@intermund let us know if the above fixed your issue?

Same error getting on running in windows
error1

Please help me out

cjus commented

@PraveenShrivastava11jan Is this still an issue for you? I've chalked this up to user error.

Thank you, I changed my redis connection inside my config file so it working.

@PraveenShrivastava11jan what config change worked for you? I have a Redis Pod on Kubernetes in Google Cloud and cannot connect to it from other pods in same cluster, with same error. I built my own image to wrap Redis' per their recommendation and overrode the bind config (first commenting and then trying 0.0.0.0) and nothing seems to work. I cannot telnet to redis on 6379 within same cluster.

Dockerfile

FROM redis
  
# Override config with local version
COPY redis.conf /usr/local/etc/redis/redis.conf

# Start server with new config
CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ]

redis.conf (relevant settings)

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# bind 127.0.0.1

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379

What is the solution for this ?

cjus commented

@mikesparr @mkrishna2025 Sorry - I'm not a Kubernetes user. @jkyberneees would you happen to know the answer to this?

@mikesparr @mkrishna2025 Sorry for late reply just try # bind 127.0.0.1 to 0.0.0.0 and protected-mode no to yes in redis config setting

@PraveenShrivastava11jan is correct. I created my own Dockerfile to edit the config file and commented out the bind params and it worked. I was also missing the containerPort param in my Kubernetes manifest. Those two solved and it works fine for a single instance (not clustered).

Working image

Working manifest (service + deployment)

apiVersion: v1
kind: Service
metadata:
  name: redis
  labels:
    component: redis
spec:
  ports:
  - port: 6379
  selector:
    component: redis

---

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: redis
  labels:
    component: redis
spec:
  template:
    metadata:
      labels:
        component: redis
    spec:
      containers:
      - name: redis
        image: mikesparr/docker-redis
        imagePullPolicy: Always
        volumeMounts:
          - name: redisdata
            mountPath: /data
            subPath: redisdata
        ports:
        - containerPort: 6379
          name: transport
          protocol: TCP
      volumes:
        - name: redisdata
          persistentVolumeClaim:
            claimName: redisdata
---
# Request a persistent volume from the cluster using a Persistent Volume Claim.
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: redisdata
  annotations:
    volume.alpha.kubernetes.io/storage-class: default
spec:
  accessModes: [ReadWriteOnce]
  resources:
    requests:
      storage: 5Gi

I downloaded GIT and updated the Redis manually... Then I created image and deployed.. It works but any alternative option to configure in Portainer itself ?