title: Node can't connect to Redis via Docker Compose
body: <p>I'm running a React app on Node and Redis via docker compose:</p>
  
  <pre><code>version: "3"
  services:
    webapp:
      build: ./
      ports:
        - "127.0.0.1:3000:9090"
      depends_on:
        - redis
      command:
        npm run start
  
    nginx:
      build: ./nginx
      ports:
        - "80:80"
      environment:
        - NGINX_HOST=127.0.0.1
        - NGINX_PORT=80
      command:
        service nginx start
  
    redis:
      image: redis
      ports:
        - "6379:6379"
      volumes:
        - ./data:/data
  </code></pre>
  
  <p>Docker file:</p>
  
  <pre><code>FROM node:alpine
  
  WORKDIR /usr/src/app
  
  COPY package.json ./
  
  RUN npm install
  COPY . .
  
  EXPOSE 9090
  RUN npm run build_prod
  </code></pre>
  
  <p>Server.js:</p>
  
  <pre><code>const redisClient = RedisClient.createClient(6379,'redis');
  </code></pre>
  
  <p>I get a Redis connection refused error when I run docker-compose up --build:</p>
  
  <pre><code>redis_1   | 1:M 15 Nov 13:55:19.865 * Ready to accept connections
  webapp_1  |
  webapp_1  | &gt; web.globalmap.fatmap.com@0.0.1 start /usr/src/app
  webapp_1  | &gt; node ./build/server.js
  webapp_1  |
  webapp_1  | events.js:193
  webapp_1  |       throw er; // Unhandled 'error' event
  webapp_1  |       ^
  webapp_1  |
  webapp_1  | Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
  webapp_1  |     at Object._errnoException (util.js:1031:13)
  webapp_1  |     at _exceptionWithHostPort (util.js:1052:20)
  webapp_1  |     at TCPConnectWrap.afterConnect [as oncomplete]
  </code></pre>
  
  <p>I would like to know how to get docker to link both containers correctly.</p>