title: PHP Redis connection via Docker - can't connect to redis container (compose setup)
body: <p>I'm trying to establish connection from a HTTP server container to Redis container using phpredis in PHP.</p>
  
  <p>This is the compose file:</p>
  
  <pre><code>version: '3'
  services:
    arcade:
      build:
        context: .
        args:
          - HOST_IP=${HOST_IP}
          - XDEBUG_PORT=${XDEBUG_PORT}
      image: arcade-dev:latest
      ports:
        - "80:80"
      volumes:
        - ../../..:/var/www/localhost/htdocs
      links:
        - marry
      networks:
        - arcade_net
    marry:
      image: mariadb
      ports:
        - "3306:3306"
      environment:
        - MYSQL_ROOT_PASSWORD=s3cr3t
      volumes:
        - arcade_data:/var/lib/mysql
      networks:
        - arcade_net
    arcade_cache:
      image: redis
      volumes:
        - arcade_cache_data:/data
      ports:
        - "6379:6379"
      networks:
        - arcade_net
  volumes:
    arcade_data: {}
    arcade_cache_data: {}
  networks:
    arcade_net:
      driver: bridge
  </code></pre>
  
  <p>This is the Redis client setup:</p>
  
  <pre><code>use Redis;
  
  final class ArcadeCache
  {
  
      public static function getClient(): Redis
      {
          $redis = new Redis();
          $redis-&gt;connect('arcade_cache');
          return $redis;
      }
  }
  </code></pre>
  
  <p>And this is a test I run using phpunit to test the connection</p>
  
  <pre><code>public function testRedisConnection(): void
  {
      $client = ArcadeCache::getClient();
  
      $client-&gt;append('testKey', 'BAZINGA');
      $bazinga = $client-&gt;get('testKey');
  
      $this-&gt;assertEquals('BAZINGA', $bazinga);
  }
  </code></pre>
  
  <p>When I run the test (using the image build for the 'arcade' service) I get the following error:</p>
  
  <pre><code>RedisException : php_network_getaddresses: getaddrinfo failed: Name does not resolve
   /opt/project/Infrastructure/ArcadeCache.php:14
   /opt/project/Tests/Infrastructure/ArcadeCacheTest.php:22
  
   Caused by
   PHPUnit\Framework\Error\Warning: Redis::connect(): php_network_getaddresses: getaddrinfo failed: Name does not resolve
  
   /opt/project/Infrastructure/ArcadeCache.php:14
   /opt/project/Tests/Infrastructure/ArcadeCacheTest.php:22
  </code></pre>
  
  <p>When I 'exec' to the http server container 'arcade_cache' hostname is properly resolved</p>
  
  <pre><code>bash-5.0# ping arcade_cache
  PING arcade_cache (172.28.0.3): 56 data bytes
  64 bytes from 172.28.0.3: seq=0 ttl=64 time=0.152 ms
  64 bytes from 172.28.0.3: seq=1 ttl=64 time=0.080 ms
  </code></pre>
  
  <p>When I try to use the IP (<code>$redis-&gt;connect('172.28.0.3');</code>) instead of hostname connection get's timed out:</p>
  
  <pre><code>RedisException : Operation timed out
   /opt/project/Infrastructure/ArcadeCache.php:14
   /opt/project/Tests/Infrastructure/ArcadeCacheTest.php:21
  
  Time: 1.05 minutes, Memory: 6.00 MB
  
  ERRORS!
  Tests: 1, Assertions: 0, Errors: 1.
  
  Process finished with exit code 2
  </code></pre>
  
  <p>Connection to DB using 'marry' hostname works fine. </p>
  
  <p>Any ideas?</p>