简体   繁体   中英

Cannot connect from host to .net core website inside docker container

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?

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); });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM