Paul Verest Paul Verest - 1 year ago 273
Node.js Question

Check/connect to Redis running within docker from Java(Spring Boot) or Node.js

I quick started with Redis on Windows PC with

docker run -p 6379:6379 redis

(Redis does not have Windows distribution, fork for Windows is not the latest version )

1:C 10 Sep 08:17:03.635 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2.3 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 1
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'

1:M 10 Sep 08:17:03.644 * The server is now ready to accept connections on port 6379

Then however I can't connect from Spring Boot app. With

got error

Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Connection refused: connect
at redis.clients.jedis.Connection.connect( ~[jedis-2.8.2.jar:na]
at redis.clients.jedis.BinaryClient.connect( ~[jedis-2.8.2.jar:na]
at redis.clients.jedis.BinaryJedis.connect( ~[jedis-2.8.2.jar:na]
at redis.clients.jedis.JedisFactory.makeObject( ~[jedis-2.8.2.jar:na]
at org.apache.commons.pool2.impl.GenericObjectPool.create( ~[commons-pool2-2.4.2.jar:2.4.2]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject( ~[commons-pool2-2.4.2.jar:2.4.2]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject( ~[commons-pool2-2.4.2.jar:2.4.2]
at redis.clients.util.Pool.getResource( ~[jedis-2.8.2.jar:na]
... 23 common frames omitted
Caused by: Connection refused: connect
at Method) ~[na:1.8.0_45]
at ~[na:1.8.0_45]
at ~[na:1.8.0_45]
at ~[na:1.8.0_45]
at ~[na:1.8.0_45]
at ~[na:1.8.0_45]
at ~[na:1.8.0_45]
at ~[na:1.8.0_45]
at redis.clients.jedis.Connection.connect( ~[jedis-2.8.2.jar:na]
... 30 common frames omitted

When trying to use Node.js with node_redis example,
I got

Error Error: Redis connection to failed - connect ECONNREFUSED

Answer Source

I'm sure you found the information, but here it is anyway. As you mentioned yourself in the comments, redis bundled their image with protected-mode set to yes (see here).

How to go around protected-mode

  • 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent.
  • 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server.
  • 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option.
  • 4) Setup a bind address or an authentication password.

source: redis-github

Build your own image

  • You could create your own image by pulling redis's and ADDing your own redis.conf to the image ?
  • Or update the start command in the Dockerfile to disable protected-mode: CMD [ "redis-server", "--protected-mode", "no" ]

You can also take a look at this Dockerfile which contains the modification suggested above (last line):

This Dockerfile is provided in a Redis issue on github, it replaces the startup command with CMD [ "redis-server", "--protected-mode", "no" ]. You could just download this Dockerfile and type:

$ docker build -t redis-unprotected:latest .
$ docker run -p 6379:6379 redis-unprotected
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download