Reputation: 745
I have searched about this but cannot find a solution... I have a .NET Core web api project and containerized it inside the docker. My host for docker is a VM in VirtualBox with CentOS 7.5. I run the container using the command:
docker run -d -name webapi -p 80:5000 netcorelnx
I can then by using the command:
docker exec -ti webapi /bin/bash
Get to that container and execute inside it:
curl localhost:5000/api/values
This returns the correct values returned by my .NET Core web api project. However when I am trying to call this from my host's browser by using the url http://localhost/api/values it says "The connection was reset". This is my dockerfile:
...
FROM microsoft/dotnet:2.1-aspnetcore-runtime-bionic AS runtime
...
ENV ASPNETCORE_URLS http://+:5000
ENTRYPOINT["dotnet", "NetCoreWebApi.dll"]
What is wrong?
Upvotes: 3
Views: 1031
Reputation: 745
As usual after many hours of investigations and posting a question I have found out a solution. The problem was in the code of the .NET core app which has been not written by me. There was a line:
.UseKestrel(options => { options.Listen(IPAddress.Loopback, 5000); });
Instead of
.UseKestrel(options => { options.Listen(IPAddress.Any, 5000); });
Upvotes: 4