title: nodejs server cannot link Redis and MongoDB in the same Docker-Compose yml file
body: <p>I built up a express server and link to mongo db and redis db.<br>
  I have used <code>docker run</code> server / mongo / redis separately and server works fine.<br>
  However, when I used <code>docker-compose</code> , it show errors</p>
  
  <blockquote>
    <p>redisdb error: { Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379 ....<br>
    MongoError: failed to connect to server [localhost:27017] on first connect ....  </p>
  </blockquote>
  
  <p>I use <code>docker ps</code> to check and all three containers are running.  </p>
  
  <p>Here is my docker-compose.yml</p>
  
  <pre><code>version: "2"
  services:
    mongo:
      image: mongo:latest
      ports:
          - "27017:27017"
    redis:
      image: redis:latest
      ports:
          - "6379:6379"
    web:
      build: .
      links:
        - mongo
        - redis
      depends_on:
        - mongo
        - redis
      ports:
        - "3000:3000"
  </code></pre>
  
  <p>Here is how I set db connection</p>
  
  <pre><code>client = redis.createClient({ "host": process.env.REDIS_PORT_6379_TCP_ADDR || 'localhost', "port": "6379" });
  mongoose.connect(`mongodb://${process.env.MONGO_PORT_27017_TCP_ADDR || 'mongodb://localhost:27017/chichat'}`);
  </code></pre>
  
  <p>I have also try <code>docker-compose stop &amp;&amp; docker-compose rm &amp;&amp; docker-compose up</code> but still fail.</p>