title: How to configure Docker port mapping to use Nginx as an upstream proxy?
body: <p><strong>Update II</strong></p>
  <p>It's now July 16th, 2015 and things have changed again. I've discovered this automagical container from Jason Wilder: <a href="https://github.com/jwilder/nginx-proxy" rel="nofollow noreferrer">https://github.com/jwilder/nginx-proxy</a> and it solves this problem in about as long as it takes to docker run the container. This is now the solution I'm using to solve this problem.</p>
  <p><strong>Update</strong></p>
  <p>It's now July of 2015 and things have change drastically with regards to networking Docker containers. There are now many different offerings that solve this problem (in a variety of ways).</p>
  <p>You should use this post to gain a basic understanding of the docker --link approach to service discovery, which is about as basic as it gets, works very well, and actually requires less fancy-dancing than most of the other solutions. It is limited in that it's quite difficult to network containers on separate hosts in any given cluster, and containers cannot be restarted once networked, but does offer a quick and relatively easy way to network containers on the same host. It's a good way to get an idea of what the software you'll likely be using to solve this problem is actually doing under the hood.</p>
  <p>Additionally, you'll probably want to also check out Docker's nascent network, Hashicorp's consul, Weaveworks weave, Jeff Lindsay's progrium/consul &amp; gliderlabs/registrator, and Google's Kubernetes.</p>
  <p>There's also the CoreOS offerings that utilize etcd, fleet, and flannel.</p>
  <p>And if you really want to have a party you can spin up a cluster to run Mesosphere, or Deis, or Flynn.</p>
  <p>If you're new to networking (like me) then you should get out your reading glasses, pop &quot;Paint The Sky With Stars — The Best of Enya&quot; on the Wi-Hi-Fi, and crack a beer — it's going to be a while before you really understand exactly what it is you're trying to do. Hint: You're trying to implement a Service Discovery Layer in your Cluster Control Plane. It's a very nice way to spend a Saturday night.</p>
  <p>It's a lot of fun, but I wish I'd taken the time to educate myself better about networking in general before diving right in. I eventually found a couple posts from the benevolent Digital Ocean Tutorial gods: Introduction to Networking Terminology and Understanding ... Networking. I suggest reading those a few times first before diving in.</p>
  <p>Have fun!</p>
  <p><strong>Original Post</strong></p>
  <p>I can't seem to grasp port mapping for <code>Docker</code> containers. Specifically how to pass requests from Nginx to another container, listening on another port, on the same server.</p>
  <p>I've got a Dockerfile for an Nginx container like so:</p>
  <pre><code>FROM ubuntu:14.04
  MAINTAINER Me &lt;me@myapp.com&gt;
  
  RUN apt-get update &amp;&amp; apt-get install -y htop git nginx
  
  ADD sites-enabled/api.myapp.com /etc/nginx/sites-enabled/api.myapp.com
  ADD sites-enabled/app.myapp.com /etc/nginx/sites-enabled/app.myapp.com
  ADD nginx.conf /etc/nginx/nginx.conf
  
  RUN echo &quot;daemon off;&quot; &gt;&gt; /etc/nginx/nginx.conf
  
  EXPOSE 80 443
  
  CMD [&quot;service&quot;, &quot;nginx&quot;, &quot;start&quot;]
  </code></pre>
  <p><br><br>
  And then the <code>api.myapp.com</code> config file looks like so:</p>
  <pre><code>upstream api_upstream{
  
      server 0.0.0.0:3333;
  
  }
  
  
  server {
  
      listen 80;
      server_name api.myapp.com;
      return 301 https://api.myapp.com/$request_uri;
  
  }
  
  
  server {
  
      listen 443;
      server_name api.mypp.com;
      
      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;
          proxy_pass http://api_upstream;
      
      }
  
  }
  </code></pre>
  <p>And then another for <code>app.myapp.com</code> as well.</p>
  <p>And then I run:</p>
  <pre><code>sudo docker run -p 80:80 -p 443:443 -d --name Nginx myusername/nginx
  </code></pre>
  <br>
  And it all stands up just fine, but the requests are not getting passed-through to the other containers/ports. And when I ssh into the Nginx container and inspect the logs I see no errors.
  <p>Any help?</p>