docs
docs copied to clipboard
Local Docker deployment API call falls
When I deploy as per this tutorial to Docker, the web app runs fine but the call to the API fails with
HttpRequestException: Connection refused (webapi:51443)
In the web app I have. WebApiBaseAddress resolves to http://webapi
Code
_apiBaseUrl = Environment.GetEnvironmentVariable("WebApiBaseAddress") ?? "http://api";
var http = new HttpClient();
ViewBag.weather = await http.GetStringAsync($"{_apiBaseUrl}/weatherforecast");
I am able to reach https://localhost:51443/swagger from the browser though (and call the GET api as well)
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 95aa8619-2154-00fb-5994-09b7a9673e03
- Version Independent ID: 182cacc8-12d1-70ac-6005-71d4f6f420d5
- Content: Build ASP.NET Core applications deployed as Linux containers into AKS/Kubernetes clusters
- Content Source: docs/architecture/containerized-lifecycle/design-develop-containerized-apps/build-aspnet-core-applications-linux-containers-aks-kubernetes.md
- Product: dotnet-architecture
- Technology: containerized-lifecycle
- GitHub Login: @nishanil
- Microsoft Alias: nanil
Hi @mrochon, thanks for bringing this to our notice, we will look into this and update you on this issue accordingly.
Linked to already raised issue #31143
The problem seems to be caused by the templated API project using app.UseHttpRedirection(). Per docs, APIs should not be using that at all: Enforce HTTPS in ASP.NET Core. I suspect the redirect response cannot be handled by the caller anyway so it fails. If you remove that line and update the project to not reference 443, you can run it in Docker and call the API.
Hi @mrochon, I have created a repo: https://github.com/dotnet-architecture/explore-docker and pushed the sample project after testing. Also, I have removed the app.UseHttpRedirection() in this sample, you can use it for your reference. Let me know if you need more help.
The issue can be closed now.
Fixed by #31925