title: Trying to connect to Redis returns an ECONNREFUSED
body: <p>I have the following <code>docker-compose.yml</code>:</p>
  
  <pre><code>version: '3'
  services:
    web:
      build: .
      image: webapp
      env_file: .env.docker
      ports:
        - "3000:3000"
      links:
        - redis
        - mongo
    redis:
      image: "redis:alpine"
    mongo:
      image: "mongo"
  </code></pre>
  
  <p>And I'm using the following env variables to connect to Mongo and Redis</p>
  
  <pre><code>REDIS_URL=redis://redis:6379
  DATABASE_URL=mongodb://mongo:27017/webapp
  </code></pre>
  
  <p>With this configuration, when the app starts it can connect to the Mongo container, but it fails to connect to Redis with the following error:</p>
  
  <pre><code>Error: connect ECONNREFUSED 127.0.0.1:6379
  </code></pre>
  
  <p>I tried exposing and mapping the ports:</p>
  
  <pre><code>    expose:
        - "6379"
      ports:
        - "6379:6379"
  </code></pre>
  
  <p>but it still doesn't solve the issue. Mapping the ports I can use redis-cli to connect to Redis, so I know the container is running.</p>
  
  <p>Any clues?</p>
  
  <p>EDIT: Running the webapp on my machine without Docker works normally. I tried both, native Redis and Mongo as well as running with the <code>docker-compose</code> below commenting out the <code>web</code> section and mapping the ports.</p>
  
  <p>EDIT 2: Output of <code>lsof</code></p>
  
  <pre><code>COMMAND    PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
  com.docke 3136 JayC   20u  IPv4 0x7dac4a08aadc94c9      0t0  TCP *:6379 (LISTEN)
  com.docke 3136 JayC   21u  IPv6 0x7dac4a08bbf50781      0t0  TCP localhost:6379 (LISTEN)
  </code></pre>
  
  <p>EDIT 3: Adding where the app connects to Redis:</p>
  
  <pre><code>const { RedisPubSub } = require('graphql-redis-subscriptions');
  
  console.log(`-------------- REDIS_URL: ${process.env.REDIS_URL} --------------`);
  
  const engine = new RedisPubSub({
      connection: {
          url: process.env.REDIS_URL,
      },
      connectionListener: err =&gt; {
          if (err) {
              Logger.sys.error(
                  `redis connection failed at ${process.env.REDIS_URL}`,
              );
              Logger.sys.error(err);
          } else {
              Logger.sys.info(
                  `pubsub connected to redis at ${process.env.REDIS_URL}`,
              );
          }
      },
  });
  </code></pre>
  
  <p>The log output:</p>
  
  <pre><code>-------------- REDIS_URL: redis://redis:6379 --------------
  2018-06-05T13:21:37.658Z - error: redis connection failed at redis://redis:6379
  2018-06-05T13:21:37.659Z - error: { Error: connect ECONNREFUSED 127.0.0.1:6379
      at Object._errnoException (util.js:1022:11)
      at _exceptionWithHostPort (util.js:1044:20)
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
    code: 'ECONNREFUSED',
    errno: 'ECONNREFUSED',
    syscall: 'connect',
    address: '127.0.0.1',
    port: 6379 }
  </code></pre>