redis connect timeout to remote server in a docker

2019-07-25 09:09发布

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条回答
Anthone
2楼-- · 2019-07-25 09:29

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

查看更多
登录 后发表回答