title: 502 bad gateway with nginx and node inside docker
body: <p>I'm trying to run node and nginx each inside their own docker containers and proxy from nginx to node. I tried the configuration below <em>without docker</em> at first and it worked. However when using docker it's not working and gives <code>Status Code:502 Bad Gateway</code> when trying to connect to <code>http://localhost/</code>.</p>
  
  <p><strong>node server</strong></p>
  
  <pre><code>var http = require('http');
  http.createServer(function (req, res) {
      res.setHeader('content-type', 'text/html');
      res.setHeader('Access-Control-Allow-Origin', '*');
      res.setHeader('Access-Control-Request-Headers', '*');
      res.setHeader('Access-Control-Request-Method', '*');
      res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');
      res.setHeader('Access-Control-Allow-Headers', '*');
      res.end('&lt;html&gt;Hey&lt;/html&gt;');
  }).listen(3001);
  </code></pre>
  
  <p><strong>docker-compose.yml</strong></p>
  
  <pre><code>version: '3'
  services:
    app:
      build: ./servers
    nginx:
      build: ./nginx
      depends_on: 
        - app
      links:
        - app
      volumes:
        - ./nginx/conf:/etc/nginx/conf.d:ro
      ports: 
        - 80:80
  </code></pre>
  
  <p><strong>nginx conf</strong></p>
  
  <pre><code>server {
          listen 80;
          listen [::]:80;
  
          location / {
                  proxy_pass http://app;
          }
  }
  </code></pre>
  
  <p><strong>app dockerfile</strong></p>
  
  <pre><code>FROM node:alpine
  RUN mkdir /app/
  COPY ./server.js /app
  EXPOSE 3001
  WORKDIR /app
  CMD node server
  </code></pre>
  
  <p><strong>nginx dockerfile</strong></p>
  
  <pre><code>FROM nginx:alpine
  RUN rm /etc/nginx/conf.d/*
  </code></pre>