Connect to redis from another container in docker

2019-08-08 23:07发布

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条回答
一夜七次
2楼-- · 2019-08-08 23:28

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>".

查看更多
登录 后发表回答