title: Docker dotnet core nginx proxy 502
body: <p>I need to use dotnet core and nginx proxy server. I have two simple images and docker compose file. Dotnet app works well with correct ports. But when I use it with nginx, It is map to 80 I think. Nginx throw error 502.</p>
  
  <p>My steps:</p>
  
  <ol>
  <li>Create docker-compose file from: <a href="https://github.com/jwilder/nginx-proxy" rel="nofollow noreferrer">https://github.com/jwilder/nginx-proxy</a></li>
  <li>Create dotnet app image with: <em>docker build --no-cache=true -t dotnetcoreimage .</em></li>
  <li><em>docker-compose up</em></li>
  </ol>
  
  <p>Here is my app langsettings:</p>
  
  <pre><code>{
    "iisSettings": {
      "windowsAuthentication": false,
      "anonymousAuthentication": true,
      "iisExpress": {
        "applicationUrl": "http://*:5000/",
        "sslPort": 0
      }
    },
    "profiles": {
      "IIS Express": {
        "commandName": "IISExpress",
        "launchBrowser": true,
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Development"
        }
      },
      "IIS Express (Production)": {
        "commandName": "IISExpress",
        "launchBrowser": true,
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Production"
        }
      }
    }
  }
  </code></pre>
  
  <p>App Docker file:</p>
  
  <pre><code># FROM microsoft/dotnet:latest
  FROM microsoft/aspnetcore-build
  
  #Update everytihing
  RUN apt-get -qq update &amp;&amp; apt-get -qq -y install bzip2
  
  #remove force apt lists
  RUN rm -rf /var/lib/apt/lists/*
  
  #for secure, copy to app folder
  COPY . /app
  
  RUN rm -Rf /app/node_modules
  
  RUN rm -Rf /app/bower_components
  
  #set workdir
  WORKDIR /app
  
  #set ASPNETCORE_ENVIRONMENT to Production
  ENV ASPNETCORE_ENVIRONMENT "Production"
  
  #restore packages
  RUN ["dotnet", "restore"]
  
  #build c#
  RUN ["dotnet", "build"]
  
  #npm install dependencies (webpack etc.)
  RUN ["npm", "install"]
  
  #run npm task webpack-prod
  RUN ["npm", "run", "webpack-prod"]
  
  EXPOSE 5000/tcp
  
  # command to run
  CMD ["dotnet", "run", "--server.urls", "http://*:5000"]
  </code></pre>
  
  <p><strong>docker-compose.yml</strong></p>
  
  <pre><code>version: '2'
  services:
    nginx-proxy:
      image: jwilder/nginx-proxy
      container_name: nginx-proxy
      ports:
        - "80:80"
      volumes:
        - /var/run/docker.sock:/tmp/docker.sock:ro
  
    mujcykloweb:
      image: mujcykloweb
      container_name: mujcyklowebcontainer       
      environment:
        - VIRTUAL_HOST=localhost
  </code></pre>
  
  <p>When u run: <em>docker-compose up</em> and go to <em><a href="http://localhost" rel="nofollow noreferrer">http://localhost</a></em></p>
  
  <pre><code>Creating network "cykloweb_default" with the default driver
  Creating nginx-proxy
  Creating mujcyklowebcontainer
  Attaching to mujcyklowebcontainer, nginx-proxy
  nginx-proxy    | forego     | starting nginx.1 on port 5000
  nginx-proxy    | forego     | starting dockergen.1 on port 5100
  nginx-proxy    | dockergen.1 | 2017/01/14 16:16:36 Generated '/etc/nginx/conf.d/default.conf' from 2 containers
  nginx-proxy    | dockergen.1 | 2017/01/14 16:16:36 Running 'nginx -s reload'
  nginx-proxy    | dockergen.1 | 2017/01/14 16:16:36 Watching docker events
  nginx-proxy    | dockergen.1 | 2017/01/14 16:16:36 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
  mujcyklowebcontainer | Project app (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
  mujcyklowebcontainer | Running Environment: Production
  mujcyklowebcontainer | info: Microsoft.Extensions.DependencyInjection.DataProtectionServices[0]
  mujcyklowebcontainer |       User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
  mujcyklowebcontainer | Hosting environment: Production
  mujcyklowebcontainer | Content root path: /app
  mujcyklowebcontainer | Now listening on: http://+:80
  mujcyklowebcontainer | Application started. Press Ctrl+C to shut down.
  nginx-proxy    | nginx.1    | 2017/01/14 16:16:58 [error] 25#25: *1 no live upstreams while connecting to upstream, client: 172.19.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://334389048b872a533002b34d73f8c29fd09efc50/", host: "localhost:5050"
  nginx-proxy    | nginx.1    | localhost 172.19.0.1 - - [14/Jan/2017:16:16:58 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36"
  nginx-proxy    | nginx.1    | localhost 172.19.0.1 - - [14/Jan/2017:16:16:58 +0000] "GET /favicon.ico HTTP/1.1" 502 575 "http://localhost:5050/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36"
  nginx-proxy    | nginx.1    | 2017/01/14 16:16:58 [error] 25#25: *1 no live upstreams while connecting to upstream, client: 172.19.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "http://334389048b872a533002b34d73f8c29fd09efc50/favicon.ico", host: "localhost:5050", referrer: "http://localhost:5050/"
  nginx-proxy    | nginx.1    | 2017/01/14 16:17:32 [error] 25#25: *1 no live upstreams while connecting to upstream, client: 172.19.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://334389048b872a533002b34d73f8c29fd09efc50/", host: "localhost:5050"
  nginx-proxy    | nginx.1    | localhost 172.19.0.1 - - [14/Jan/2017:16:17:32 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36"
  nginx-proxy    | nginx.1    | 2017/01/14 16:17:32 [error] 25#25: *1 no live upstreams while connecting to upstream, client: 172.19.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "http://334389048b872a533002b34d73f8c29fd09efc50/favicon.ico", host: "localhost:5050", referrer: "http://localhost:5050/"
  nginx-proxy    | nginx.1    | localhost 172.19.0.1 - - [14/Jan/2017:16:17:32 +0000] "GET /favicon.ico HTTP/1.1" 502 575 "http://localhost:5050/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36"
  </code></pre>
  
  <p>I think, that web app has bad port mapping, because 80 should have nginx or not? (Now listening on: <a href="http://+:80" rel="nofollow noreferrer">http://+:80</a>)</p>
  
  <p>I tried to <em>docker composive --force-recreate</em> , stop/start docker and restart pc but the same problem.</p>
  
  <p>Where is problem please?
  Thank you for your time.</p>