title: .NET Core API: "local host refused to connect " when run via Docker
body: <p>I am trying to run a simple web api via docker.</p>
  
  <p>I have followed all the steps mentioned in the <a href="https://docs.docker.com/engine/examples/dotnetcore/" rel="nofollow noreferrer">docs</a>. </p>
  
  <pre><code>FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
  WORKDIR /app
  
  # Copy csproj and restore as distinct layers
  COPY *.csproj ./
  RUN dotnet restore
  
  # Copy everything else and build
  COPY . ./
  RUN dotnet publish -c Release -o out
  
  # Build runtime image
  FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
  WORKDIR /app
  COPY --from=build-env /app/out .
  ENTRYPOINT ["dotnet", "aspnetapp.dll"]
  </code></pre>
  
  <p><strong>Screenshot:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/JhZAc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JhZAc.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/bS8PU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bS8PU.png" alt="enter image description here"></a></p>
  
  <p><strong>Commands that I am using to run api via docker:</strong></p>
  
  <pre><code>docker build -t aspnetapp .
  docker run -d -p 8080:80 --name myapp aspnetapp
  </code></pre>
  
  <p><strong>Please note that the api works when I execute the following commands in command line so there is likely nothing wring with the api itself:</strong></p>
  
  <pre><code>dotnet publish -c Release -o out
  dotnet run out/ApiForDocker.dll
  </code></pre>
  
  <p>EDIT:</p>
  
  <p><a href="https://i.stack.imgur.com/Y894j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y894j.png" alt="enter image description here"></a></p>
  
  <p><strong>launchSettings</strong></p>
  
  <pre><code>{
    "$schema": "http://json.schemastore.org/launchsettings.json",
    "iisSettings": {
      "windowsAuthentication": false, 
      "anonymousAuthentication": true, 
      "iisExpress": {
        "applicationUrl": "http://localhost:63852",
        "sslPort": 44318
      }
    },
    "profiles": {
      "IIS Express": {
        "commandName": "IISExpress",
        "launchBrowser": true,
        "launchUrl": "api/values",
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Development"
        }
      },
      "ApiForDocker": {
        "commandName": "Project",
        "launchBrowser": true,
        "launchUrl": "api/values",
        "applicationUrl": "https://localhost:5001;http://localhost:5000",
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Development"
        }
      }
    }
  }
  </code></pre>