Connect to redis from another container in docker

浪子不回头ぞ 提交于 2019-12-13 19:32:46

问题


I have app, that used Tornado and tornado-redis. [image "app" in docker images] I start redis:

docker run --name some-redis -d redis

Then I want to link my app with redis:

docker run --name some-app --link some-redis:redis app

And I have error:

Traceback (most recent call last):
  File "./app.py", line 41, in <module>
    c.connect()
  File "/usr/local/lib/python3.4/site-packages/tornadoredis/client.py", line 333
, in connect
    self.connection.connect()
  File "/usr/local/lib/python3.4/site-packages/tornadoredis/connection.py", line
 79, in connect
    raise ConnectionError(str(e))
tornadoredis.exceptions.ConnectionError: [Errno 111] Connection refused

I have tested my code with local tornado and redis, and it works. The problem in

c = tornadoredis.Client()
c.connect()

Why my app cant connet to redis-container? How to fix that? I use standart port 6379.

Thanks!


回答1:


tornadoredis attempts to use redis on localhost. (See source here)

So you need to inform tornadoredis where redis is running (since to the docker image it is not running on localhost).

For example:

c = tornadoredis.Client(host="<hostname>")
c.connect()

In your specific case, substitute "redis" for "<hostname>".



来源:https://stackoverflow.com/questions/31073614/connect-to-redis-from-another-container-in-docker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!