title: Docker - nginx proxy - access hosts between containers
body: <p>I have web application. </p>
  
  <ol>
  <li>Public web app (app1)</li>
  <li>api web app (app2)</li>
  </ol>
  
  <p>I make docker configuration for this apps. Each application in its container. To access this applications from web, configured container with nginx, where nginx proxy all requests.<br>
  So i can run - <a href="http://app1.dev/" rel="nofollow">http://app1.dev/</a> and <a href="http://app2.dev/" rel="nofollow">http://app2.dev/</a></p>
  
  <p>But i need have access from app1 to <a href="http://app2.dev/" rel="nofollow">http://app2.dev/</a> (access hosts app2.dev from app1 container).</p>
  
  <p>Ping (from app1 container):</p>
  
  <pre><code>PING app2.dev (127.0.53.53) 56(84) bytes of data.
  64 bytes from 127.0.53.53: icmp_seq=1 ttl=64 time=0.027 ms
  64 bytes from 127.0.53.53: icmp_seq=2 ttl=64 time=0.038 ms
  64 bytes from 127.0.53.53: icmp_seq=3 ttl=64 time=0.038 ms
  </code></pre>
  
  <p>What i should configure else, to have access to <a href="http://app2.dev/" rel="nofollow">http://app2.dev/</a> host from app1 container?</p>
  
  <p>Nginx proxy config</p>
  
  <pre><code>upstream app1_upstream {
      server app1;
  }
  upstream app1_upstream {
      server app2;
  }
  server {
      listen 80;
  
      server_name app1.dev
                  app2.dev;
  
      location / {
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_cache_bypass $http_upgrade;
  
          if ($host = "app1.dev") {
              proxy_pass http://app1;
          }
  
          if ($host = "app2.dev") {
              proxy_pass http://app2;
          }
      }
  
      error_log  /var/log/nginx/proxy_error.log;
      access_log /var/log/nginx/proxy_access.log;
  }
  </code></pre>
  
  <p>Docker compose</p>
  
  <pre><code>version: '2'
  services:
      proxy:
          build: ./proxy/
          ports:
              - "80:80"
              - "443:443"
          links:
              - app1
              - app2
              - app1:app1
              - app2:app2
          hostname: proxy
  
      app1:
          build: ./app1/
          volumes:
              - ../app1/:/var/www/app1
          hostname: app1
  
      app2:
          build: ./app2/
          volumes:
              - ../app2/:/var/www/app2
          hostname: app2
  </code></pre>
  
  <p><code>docker-compose ps</code></p>
  
  <pre><code>app1      /sbin/my_init  Up      80/tcp                                   
  app2     /sbin/my_init  Up      80/tcp                                   
  proxy_1   /sbin/my_init  Up      0.0.0.0:443-&gt;443/tcp, 0.0.0.0:80-&gt;80/tcp
  </code></pre>