简体   繁体   English

从Docker中的另一个容器连接到Redis

[英]Connect to redis from another container in docker

I have app, that used Tornado and tornado-redis . 我有使用Tornado和tornado-redis的应用程序。 [image "app" in docker images ] I start redis: [ docker images图像“ app”]我开始redis:

docker run --name some-redis -d redis

Then I want to link my app with redis: 然后我想将我的应用程序与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. 我已经用本地龙卷风和redis测试了我的代码,并且可以正常工作。 The problem in 问题在

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

Why my app cant connet to redis-container? 为什么我的应用程序无法连接到Redis容器? How to fix that? 如何解决? I use standart port 6379. 我使用标准端口6379。

Thanks! 谢谢!

tornadoredis attempts to use redis on localhost . tornadoredis尝试在localhost上使用redis。 (See source here ) (请参见此处的源代码)

So you need to inform tornadoredis where redis is running (since to the docker image it is not running on localhost ). 因此,您需要通知tornadoredis在何处运行(因为tornadoredis镜像未在localhost运行)。

For example: 例如:

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

In your specific case, substitute "redis" for "<hostname>" . 在您的特定情况下,将"redis"替换为"<hostname>"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM