title: Docker and identity server 4, api, angular : Cannot assign requested address
body: <p>I set up a docker in macos (but should work in any environement): </p>
  
  <p>1) Identity server 4 running in a container</p>
  
  <p>launchsettings:</p>
  
  <pre><code>"MacTest": {
    "commandName": "Project",
    "environmentVariables": {
      "ASPNETCORE_HTTPS_PORT": "44000",
      "ASPNETCORE_ENVIRONMENT": "MacTest"
    },
    "applicationUrl": "https://0.0.0.0:44000" 
  }
  </code></pre>
  
  <p>dockerfile (dockerfile-idp): </p>
  
  <pre><code>ENTRYPOINT ["dotnet", "run", "--launch-profile", "MacTest"]
  </code></pre>
  
  <p>composer:</p>
  
  <pre><code>identityserver:
  image: idp
  build: 
    context: .
    dockerfile: ./docker/dockerfile-idp
  ports:
   - "9000:9000"
   - "44000:44000"
  volumes:
   - .:/idp
  </code></pre>
  
  <p>2) An APIsource authenticate on identity server running on an container:
  launchsettings: </p>
  
  <pre><code>"MacTest": {
    "commandName": "Project",
    "environmentVariables": {
      "ASPNETCORE_ENVIRONMENT": "MacLocalTest",
      "ASPNETCORE_HTTPS_PORT": 44100
    },
    "applicationUrl": "https://0.0.0.0:44100"
  }
  </code></pre>
  
  <p>dockerfile (dockerfile-api): </p>
  
  <pre><code>ENTRYPOINT ["dotnet", "run", "--launch-profile", "MacTest"]
  </code></pre>
  
  <p>composer:</p>
  
  <pre><code>  api:
  image: api
  build: 
    context: .
    dockerfile: ./docker/dockerfile-api
  ports:
   - "9100:9100"
   - "44100:44100"
  volumes:
   - .:/api 
  </code></pre>
  
  <p>3) An angular app running on other container</p>
  
  <p>Problem: 
  Angular login page can connect to identity server and can get the token that works... OK</p>
  
  <p>It can can Api and retrieve public data... OK</p>
  
  <p>BUT it can't call a protected method with Authorize. I start believing that the api try to authenticate itself from identity server but for some reason it can't access to the server.</p>
  
  <pre><code>[HttpGet("info")]
  [AppAuthorize]   =&gt; THIS NOT WORK 
  public IActionResult Info()
  {
  ...
  } 
  </code></pre>
  
  <p>ERROR:</p>
  
  <pre><code>System.Net.Sockets.SocketException (99): Cannot assign requested address
     at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
  HttpRequestException: Cannot assign requested address
  System.Net.Http.ConnectHelper.ConnectAsync(string host, int port, CancellationToken cancellationToken)
  System.Threading.Tasks.ValueTask&lt;TResult&gt;.get_Result()
  System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  System.Threading.Tasks.ValueTask&lt;TResult&gt;.get_Result()
  System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask&lt;ValueTuple&lt;HttpConnection, HttpResponseMessage&gt;&gt; creationTask)
  System.Threading.Tasks.ValueTask&lt;TResult&gt;.get_Result()
  System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, bool doRequestAuth, CancellationToken cancellationToken)
  System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task&lt;HttpResponseMessage&gt; sendTask, HttpRequestMessage request, CancellationTokenSource cts, bool disposeCts)
  Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(string address, CancellationToken cancel)
  
  Show raw exception details
  System.Net.Http.HttpRequestException: Cannot assign requested address ---&gt; System.Net.Sockets.SocketException: Cannot assign requested address
     at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
     --- End of inner exception stack trace ---
     at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
     at System.Threading.Tasks.ValueTask`1.get_Result()
     at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
     at System.Threading.Tasks.ValueTask`1.get_Result()
     at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
     at System.Threading.Tasks.ValueTask`1.get_Result()
     at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
     at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
     at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
     at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
  IOException: IDX20804: Unable to retrieve document from: 'https://localhost:44000/.well-known/openid-configuration'.
  Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(string address, CancellationToken cancel)
  Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(string address, IDocumentRetriever retriever, CancellationToken cancel)
  Microsoft.IdentityModel.Protocols.ConfigurationManager&lt;T&gt;.GetConfigurationAsync(CancellationToken cancel)
  
  Show raw exception details
  System.IO.IOException: IDX20804: Unable to retrieve document from: 'https://localhost:44000/.well-known/openid-configuration'. ---&gt; System.Net.Http.HttpRequestException: Cannot assign requested address ---&gt; System.Net.Sockets.SocketException: Cannot assign requested address
     at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
     --- End of inner exception stack trace ---
     at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
     at System.Threading.Tasks.ValueTask`1.get_Result()
     at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
     at System.Threading.Tasks.ValueTask`1.get_Result()
     at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
     at System.Threading.Tasks.ValueTask`1.get_Result()
     at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
     at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
     at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
     at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
     --- End of inner exception stack trace ---
     at Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(String address, CancellationToken cancel)
     at Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(String address, IDocumentRetriever retriever, CancellationToken cancel)
     at Microsoft.IdentityModel.Protocols.ConfigurationManager`1.GetConfigurationAsync(CancellationToken cancel)
  InvalidOperationException: IDX20803: Unable to obtain configuration from: 'https://localhost:44000/.well-known/openid-configuration'.
  Microsoft.IdentityModel.Protocols.ConfigurationManager&lt;T&gt;.GetConfigurationAsync(CancellationToken cancel)
  Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
  Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()
  Microsoft.AspNetCore.Authentication.AuthenticationHandler&lt;TOptions&gt;.AuthenticateAsync()
  Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, string scheme)
  IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationHandler.HandleAuthenticateAsync() in C:\local\identity\server4\AccessTokenValidation\src\IdentityServerAuthenticationHandler.cs
  Microsoft.AspNetCore.Authentication.AuthenticationHandler&lt;TOptions&gt;.AuthenticateAsync()
  Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, string scheme)
  Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
  Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.InvokeCore(HttpContext context)
  Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
  Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
  </code></pre>
  
  <p>I'm trying to set a new wetwork setting but quite challanging, I don't even know if the network is the problem. Anybody can help?</p>
  
  <p>Thnak you</p>