redis connect timeout to remote server in a docker

a 夏天 提交于 2019-12-13 01:25:01

问题


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> 

回答1:


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



来源:https://stackoverflow.com/questions/36784812/redis-connect-timeout-to-remote-server-in-a-docker

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