Answers: <p>You're creating the following network and your services get IPs from this range.</p>
  <pre><code>  redisnet:
      driver: bridge
      ipam:
        config:
          - subnet: 10.0.0.0/16
  </code></pre>
  <p>Which container are you connecting to? Does the IP get resolved correctly? Does your host machine know how to reach the 10.0.0.0/16 subnet? You need to have a entry in your route table that sends the traffic for 10.0.0.0/16 through the bridge adapter created for the <code>redisnet</code> network.</p>
  
Answers: CC BY-SA 4.0
Answers: 2022-01-31T14:37:33.583Z
Answers: I guess I don't know how to config my host machine to use this subnet
Answers: itamar
Answers: CC BY-SA 4.0
Answers: 2022-01-31T15:19:05.200Z
Answers: Use the route -n command to see all your routes. Check if one exists for 10.0.0.0/16 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 10.0.0.0/16 subnet. Use the ip route add 10.0.0.0/16 dev <device-you-found> command to add the route.
Answers: theUndying
Answers: CC BY-SA 4.0
Answers: 2022-01-31T13:10:41.887Z
Answers: 2022-01-31T13:19:38.967Z
Answers: 2022-01-31T13:19:38.967Z
Answers: theUndying
Body: <p>I'm running this <a href="https://github.com/itsmetommy/docker-redis-cluster/blob/master/docker-compose.yaml" rel="nofollow noreferrer">docker-compose.yaml</a> on my machine (Mac with docker desktop) but am not able to connect the cluster with <code>redis-cli</code>.</p>
  <p>I'm running it with</p>
  <pre><code>docker-compose up --build
  </code></pre>
  <p>I'm able to run <code>redis-cli</code> <strong>from within the containers</strong> like</p>
  <pre><code>❯ docker exec -it docker-redis-cluster_redis-1_1 redis-cli -c -p 7001                                                                                       (eks-dev-blue/itamar)
  127.0.0.1:7001&gt; cluster nodes
  c9c01ea75f43780f36f3dca445410c1c902bda0b 10.0.0.16:7006@17006 slave cc69a5c2467fff36daa62acefc70b4b49d7a22a6 0 1643633817569 2 connected
  cc69a5c2467fff36daa62acefc70b4b49d7a22a6 10.0.0.12:7002@17002 master - 0 1643633816000 2 connected 5461-10922
  9c1d48c16402c651578b4722ceb699aa0effa392 10.0.0.11:7001@17001 myself,master - 0 1643633816000 1 connected 0-5460
  c83836c357ce77cf845cda983aa76aa7942e2489 10.0.0.14:7004@17004 slave 5bdf05a8d332646ee76ff0da64fb97570cf7117e 0 1643633816558 3 connected
  5bdf05a8d332646ee76ff0da64fb97570cf7117e 10.0.0.13:7003@17003 master - 0 1643633817974 3 connected 10923-16383
  115b037e3dc2de23389a3b085b4242b63bfa887a 10.0.0.15:7005@17005 slave 9c1d48c16402c651578b4722ceb699aa0effa392 0 1643633817000 1 connected
  </code></pre>
  <p>But I'm not able to communicate with the cluster from my host machine:</p>
  <pre><code>❯ redis-cli -c -h localhost -p 7001                                                                                                                                       (eks-prod-blue/prod)
  127.0.0.1:7001&gt; cluster nodes
  Error: Server closed the connection
  </code></pre>
  <p>What am I missing? Is it a missing network\ports config?</p>
  
Comments: CC BY-SA 4.0
Comments: 2022-01-31T08:02:09.960Z
Comments: 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.
Comments: Community
Tags: <docker-compose><redis>
Title: How to connect my host to Redis cluster network on docker-compose
UserDisplayName: itamar
ThreadText: # How to connect my host to Redis cluster network on docker-compose
  
  (Asked by: username_0 on 2022-01-31)
  
  I'm running this [docker-compose.yaml](https://github.com/itsmetommy/docker-redis-cluster/blob/master/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/username_0)
  127.0.0.1:7001> cluster nodes
  c9c01ea75f43780f36f3dca445410c1c902bda0b 10.0.0.16:7006@17006 slave cc69a5c2467fff36daa62acefc70b4b49d7a22a6 0 1643633817569 2 connected
  cc69a5c2467fff36daa62acefc70b4b49d7a22a6 10.0.0.12:7002@17002 master - 0 1643633816000 2 connected 5461-10922
  9c1d48c16402c651578b4722ceb699aa0effa392 10.0.0.11:7001@17001 myself,master - 0 1643633816000 1 connected 0-5460
  c83836c357ce77cf845cda983aa76aa7942e2489 10.0.0.14:7004@17004 slave 5bdf05a8d332646ee76ff0da64fb97570cf7117e 0 1643633816558 3 connected
  5bdf05a8d332646ee76ff0da64fb97570cf7117e 10.0.0.13:7003@17003 master - 0 1643633817974 3 connected 10923-16383
  115b037e3dc2de23389a3b085b4242b63bfa887a 10.0.0.15:7005@17005 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)
  127.0.0.1:7001> cluster nodes
  Error: Server closed the connection
  
  ```
  
  What am I missing? Is it a missing network\ports config?
  
  **Tags:** docker-compose, redis
  
  > **Comments:**
  > **username_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.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2022-01-31. Score: 0
  
  You're creating the following network and your services get IPs from this range.
  
  ```
    redisnet:
      driver: bridge
      ipam:
        config:
          - subnet: 10.0.0.0/16
  
  ```
  
  Which container are you connecting to? Does the IP get resolved correctly? Does your host machine know how to reach the 10.0.0.0/16 subnet? You need to have a entry in your route table that sends the traffic for 10.0.0.0/16 through the bridge adapter created for the `redisnet` network.
  
  > **Comments:**
  > **username_0**: I guess I don't know how to config my host machine to use this subnet  
  > **username_2**: Use the route -n command to see all your routes. Check if one exists for 10.0.0.0/16 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 10.0.0.0/16 subnet. Use the ip route add 10.0.0.0/16 dev <device-you-found> command to add the route.  
  
  ---
  
  