title: Docker networking reverse proxy without docker-compose
body: <h1>The challenge</h1>
  
  <p>As described, I want to accomplish the same goal with docker itself as I would with the help of docker-compose.<br>
  I want to get a deeper understanding of docker and enable the ability to work with docker on platforms, where docker-compose is not an option.</p>
  
  <h2>What I do currently (with docker-compose)</h2>
  
  <h3>1)</h3>
  
  <p>I use this docker-compose file:</p>
  
  <pre><code>---
  version: '3'
  
  services:
      app:
          build: .
  
      proxy:
          build: docker/proxy
          ports:
              - "80:80"
  </code></pre>
  
  <p>The "app" service starts a container which runs node on port 3002 (is exposed in the dockerfile)</p>
  
  <p>The "proxy" service starts a container which runs an nginx with - among others - the following conf:</p>
  
  <pre><code>server {
      listen 80;
      server_name app;
  
      location / {
          proxy_pass  http://app:3002;
      }
  }
  </code></pre>
  
  <h3>2)</h3>
  
  <p>Then I add this to the /etc/hosts of my host pc:</p>
  
  <pre><code>127.0.0.1   app
  </code></pre>
  
  <h3>3)</h3>
  
  <p>Now I run <code>docker-compose up</code> and vist <a href="http://app" rel="nofollow noreferrer">http://app</a> , which hits the node app.</p>
  
  <p>Nice and simple, right?</p>
  
  <hr>
  
  <p>Now I want to do the same only with docker.</p>
  
  <h2>What I've tried</h2>
  
  <h3>1 using the same nginx configuration.</h3>
  
  <h3>2 Starting the containers with a bash script</h3>
  
  <p>To accomplish this I</p>
  
  <ol>
  <li>Created a network</li>
  <li>Add the network to both containers</li>
  <li>Setting up "app"-container hostname, network-alias and dns-search to "app" (because I hoped one of the options would help)</li>
  </ol>
  
  <p>Here the script:</p>
  
  <pre><code>docker network create --driver bridge dockertest_nw
  
  docker build -t dockertest_app .
  docker create \
      --name dockertest_app_con \
      --network dockertest_nw \
      --hostname app \
      --network-alias=app \
      --dns-search=app \
      dockertest_app
  
  docker build -t dockertest_proxy ./docker/proxy/
  docker create \
      --name dockertest_proxy_con \
      --network dockertest_nw \
      --hostname proxy \
      --network-alias=proxy \
      --dns-search=proxy \
      -p 80:80 \
      dockertest_proxy
  
  docker start dockertest_proxy_con
  docker start dockertest_app_con
  </code></pre>
  
  <p>Unfortunately, this doesn't work.</p>
  
  <p>I also know there is a dns service from docker which docker-compose somehow uses and I should also use it on some way?</p>
  
  <p>Could any one give some suggestions?</p>
  
  <hr>
  
  <p><strong>Update:</strong>
  Just the info I got the following logs from the nginx container, which i would say shows the nginx doesn't can resolve "app" :</p>
  
  <pre><code>172.18.0.1 - - [13/Apr/2017:14:49:06 +0000] "GET / HTTP/1.1" 502 576 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36" "-"
  2017/04/13 14:49:06 [error] 5#5: *13 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: app, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3002/", host: "app"
  </code></pre>