I'm running this docker-compose.yaml on my machine (Mac with docker desktop) but am not able to connect the cluster with redis-cli.

I'm running it with

docker-compose up --build

I'm able to run redis-cli from within the containers like

❯ docker exec -it docker-redis-cluster_redis-1_1 redis-cli -c -p 7001                                                                                       (eks-dev-blue/itamar)> cluster nodes
c9c01ea75f43780f36f3dca445410c1c902bda0b slave cc69a5c2467fff36daa62acefc70b4b49d7a22a6 0 1643633817569 2 connected
cc69a5c2467fff36daa62acefc70b4b49d7a22a6 master - 0 1643633816000 2 connected 5461-10922
9c1d48c16402c651578b4722ceb699aa0effa392 myself,master - 0 1643633816000 1 connected 0-5460
c83836c357ce77cf845cda983aa76aa7942e2489 slave 5bdf05a8d332646ee76ff0da64fb97570cf7117e 0 1643633816558 3 connected
5bdf05a8d332646ee76ff0da64fb97570cf7117e master - 0 1643633817974 3 connected 10923-16383
115b037e3dc2de23389a3b085b4242b63bfa887a slave 9c1d48c16402c651578b4722ceb699aa0effa392 0 1643633817000 1 connected

But I'm not able to communicate with the cluster from my host machine:

❯ redis-cli -c -h localhost -p 7001                                                                                                                                       (eks-prod-blue/prod)> cluster nodes
Error: Server closed the connection

What am I missing? Is it a missing network\ports config?

  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Jan 31, 2022 at 8:02

1 Answer 1


You're creating the following network and your services get IPs from this range.

    driver: bridge
        - subnet:

Which container are you connecting to? Does the IP get resolved correctly? Does your host machine know how to reach the subnet? You need to have a entry in your route table that sends the traffic for through the bridge adapter created for the redisnet network.

  • I guess I don't know how to config my host machine to use this subnet
    – itamar
    Jan 31, 2022 at 14:37
  • Use the route -n command to see all your routes. Check if one exists for and which device is displayed as the gateway. If you don't see any, then you need to list all your interfaces with ifconfig -a and find the one that is of type bridge and has an address in the subnet. Use the ip route add dev <device-you-found> command to add the route.
    – theUndying
    Jan 31, 2022 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.