1

My docker version is 1.13.1. I am trying to connect to redis-server from my docker container,but I am getting connection refused error.Detailed logs are given below:

Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused at redis.clients.jedis.Connection.connect(Connection.java:207) [jedis-2.9.0.jar:] at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93) [jedis-2.9.0.jar:] at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767) [jedis-2.9.0.jar:] at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106) [jedis-2.9.0.jar:] at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:888) [commons-pool2-2.4.3.jar:2.4.3] at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:432) [commons-pool2-2.4.3.jar:2.4.3] at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:361) [commons-pool2-2.4.3.jar:2.4.3] at redis.clients.util.Pool.getResource(Pool.java:49) [jedis-2.9.0.jar:] ... 27 more Caused by: java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method) [rt.jar:1.7.0_80] at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) [rt.jar:1.7.0_80] at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) [rt.jar:1.7.0_80] at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) [rt.jar:1.7.0_80] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) [rt.jar:1.7.0_80] at java.net.Socket.connect(Socket.java:579) [rt.jar:1.7.0_80] at redis.clients.jedis.Connection.connect(Connection.java:184) [jedis-2.9.0.jar:] ... 34 more

when i give --net="host" option this error is gone,but when i give

--add-host=parent-host:`ip route show | grep docker0 | awk '{print \$9}'`

I get the error,although the container is able to connect to Db on a different VM,but not connecting to redis-server present on self hosting machine.

Shadab
  • 367
  • 3
  • 26
  • Couple of questions: Is redis running in docker? What OS are you using? – yamenk Nov 28 '17 at 10:36
  • OS is rhel 7.Redis is installed on the same host machine outside the docker.Redis & Docker is installed on the same machine. – Shadab Nov 28 '17 at 10:39

1 Answers1

0

I suspect the problem is that you are trying to connect to redis via localhost rather than parent-host. Make sure that you are connecting to redis via parent-host when creating the Jedis connection.

The reason --net=host option works, is that in this case localhost will refer to the IP of the host machine and not to that of the container.

Also, make sure that there is an enty for parent-host in /etc/hosts inside the container.

yamenk
  • 46,736
  • 10
  • 93
  • 87
  • 1
    --add-host configures that in /etc/hosts.I have tried with ip/localhost/parent-host,but not connecting. – Shadab Nov 28 '17 at 11:16