title: Redis cluster on Docker Compose with network_mode host - Unable to connect to redis-cluster
body: <p>I set up a <strong>Redis</strong> cluster with 6 nodes as follows. From the <a href="https://redis.io/topics/cluster-tutorial" rel="nofollow noreferrer">redis-cluster documentation</a>, <code>network_mode</code> <code>host</code> must be used.</p>
  <pre class="lang-yaml prettyprint-override"><code>version: &quot;3.9&quot;
      services:
          redis0:
            build:
              context: .
              dockerfile: ./DockerFile_Builders/Redis/Dockerfile-base
              args:
                PORT_CONFIG: 7000
                PORT_BUS_CONFIG: 8100
            network_mode: &quot;host&quot;
      
          redis1:
            build:
              context: .
              dockerfile: ./DockerFile_Builders/Redis/Dockerfile-base
              args:
                PORT_CONFIG: 7001
                PORT_BUS_CONFIG: 8101
            network_mode: &quot;host&quot;
      
          redis2:
            build:
              context: .
              dockerfile: ./DockerFile_Builders/Redis/Dockerfile-base
              args:
                PORT_CONFIG: 7002
                PORT_BUS_CONFIG: 8102
            network_mode: &quot;host&quot;
      
          redis3:
            build:
              context: .
              dockerfile: ./DockerFile_Builders/Redis/Dockerfile-base
              args:
                PORT_CONFIG: 7003
                PORT_BUS_CONFIG: 8103
            network_mode: &quot;host&quot;
      
          redis4:
            build:
              context: .
              dockerfile: ./DockerFile_Builders/Redis/Dockerfile-base
              args:
                PORT_CONFIG: 7004
                PORT_BUS_CONFIG: 8104
            network_mode: &quot;host&quot;
      
          redis5:
            build:
              context: .
              dockerfile: ./DockerFile_Builders/Redis/Dockerfile-base
              args:
                PORT_CONFIG: 7005
                PORT_BUS_CONFIG: 8105
            network_mode: &quot;host&quot;
      
      
          redis-cluster:
            tty: true
            build:
              context: .
              dockerfile: ./DockerFile_Builders/Redis/Dockerfile
            #hostname: redis-server
            depends_on:
              - redis1
              - redis2
              - redis3
              - redis4
              - redis5
            network_mode: &quot;host&quot;
          
          user_service:
            depends_on:
              - &quot;redis-cluster&quot;
            links:
              - &quot;redis-cluster&quot;
            build:
              context: .
              dockerfile: DockerFile_Builders/Services/User/Dockerfile
  </code></pre>
  <p>Now it is required to connect to the Redis cluster from the <code>user-service</code> container, when I try to connect using:</p>
  <pre class="lang-java prettyprint-override"><code>RedisURI masterURI = RedisURI.create(&quot;redis://redis-cluster:7001&quot;);
  </code></pre>
  <p>I get the following error:</p>
  <blockquote>
  <p>19:57:28.329 [lettuce-epollEventLoop-4-1] WARN  com.lambdaworks.redis.cluster.topology.ClusterTopologyRefresh - Unable to connect to redis-cluster/:7003
  chat_service_1          | java.util.concurrent.CompletionException: java.net.UnknownHostException: redis-cluster</p>
  </blockquote>
  <p>However, when the <code>user-service</code> is launched locally (without the docker container) and the Redis cluster is still in a Docker container, the connection is established normally using:</p>
  <pre class="lang-java prettyprint-override"><code>RedisURI masterURI = RedisURI.create(&quot;redis://localhost:7001&quot;);
  </code></pre>