Redis将超时连接到Docker中的远程服务器 [英] redis connect timeout to remote server in a docker

查看:555
本文介绍了Redis将超时连接到Docker中的远程服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在机器A中使用docker-compose启动一个redis容器。



docker-compose.yml。

  redis:
端口:
- 6379:6379
图片:redis

在机器A上,我可以使用终端中的redis-cli连接到它。

  redis-cli 
127.0.0.1:6379>

但是即使在机器A本身上,我也无法使用机器B上的A的IP来连接它。 / p>在机器B或A上的

  redis-cli -h 10.10 .10.25 
无法在10.10.10.25:6379连接到Redis:连接超时
未连接>


解决方案

这很奇怪。我可以使用A的IP在主机A和主机B上运行redis-cli。
以下是 docker ps的输出

  docker ps 
容器ID图像命令创建的状态端口NAMES
a59c39bf448e redis /entrypoint.sh redis 3分钟前向上3分钟0.0.0.0:6379->6379/tcp test_redis_1

将redis容器的端口6379映射到主机端口6379之后。redis服务应该可用于主机A的所有网络接口(0.0.0.0)。因此,您不必更改redis配置。



可以显示 docker ps的输出吗?


I start a redis container with docker-compose in machine A.

docker-compose.yml.

redis:
    ports:
    - "6379:6379"
    image: redis

on machine A, I can connect to it with redis-cli in terminal.

redis-cli 
127.0.0.1:6379> 

But I can't connect to it use A's IP on machine B even on machine A itself.

on machine B or A.

redis-cli -h 10.10.10.25
Could not connect to Redis at 10.10.10.25:6379: Connection timed out
not connected> 

解决方案

It's strange. I can run redis-cli on both host A and host B with A's IP. Following is the output of "docker ps"

docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
a59c39bf448e        redis               "/entrypoint.sh redis"   3 minutes ago       Up 3 minutes        0.0.0.0:6379->6379/tcp   test_redis_1

After mapping port 6379 of redis container to the host port 6379. The redis service should be available for all network interfaces(0.0.0.0) of host A. So you don't have to change the redis configuration.

Can you show the output of "docker ps"?

这篇关于Redis将超时连接到Docker中的远程服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆