title: Nginx reverse proxy for Docker containers
body: <p>I have a problem with reverse proxy to my Docker services. I have a local machine with IP 10.0.0.163 and with Docker stack running on it with nginx and portainer (for this question only they matter).</p>
  
  <p><strong>docker-compose.yml:</strong></p>
  
  <pre><code>...
   portainer:
      image: portainer/portainer
      ports:
        - "9000:9000"
      volumes:
        - "/var/run/docker.sock:/var/run/docker.sock"
        - "/mnt/StorageDrive/Portainer:/data"
      deploy:
        placement:
          constraints: [node.role == manager]
      networks:
        ...
        - proxy
  
   reverse-proxy:
      image: reverseproxy:latest
      ports:
        - "80:80"
      networks:
        - proxy
  
  networks:
    ...
    proxy:
  </code></pre>
  
  <p><strong>nginx.conf:</strong></p>
  
  <pre><code>worker_processes  1;  ## Default: 1
  
  events { worker_connections  1024; }
  
  http {
  
    sendfile     on;
  
    server {
      listen 80;
      allow all;
  
      location / {
        proxy_pass      http://10.0.0.163:9000;
      }
    }
  }
  </code></pre>
  
  <p><strong>Dockerfile for reverseproxy image:</strong></p>
  
  <pre><code>FROM nginx:alpine
  
  COPY nginx.conf /etc/nginx/nginx.conf
  </code></pre>
  
  <p>When trying to access 10.0.0.163 I get error 502 and logs from reverseproxy show this:</p>
  
  <pre><code>2017/10/09 07:43:02 [error] 5#5: *1 connect() failed (113: Host is unreachable) while connecting to upstream, client: 10.255.0.2, server: , request: "GET / HTTP/1.1", upstream: "http://10.0.0.163:9000/", host: "10.0.0.163"
  10.255.0.2 - - [09/Oct/2017:07:43:02 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
  </code></pre>
  
  <p>When typing 10.0.0.163:9000/ into browser - everything works fine. What is the problem? And how can I make it work with this URL </p>
  
  <pre><code>10.0.0.163/portainer/... -&gt; 10.0.0.163:9000/...
  </code></pre>