dockerasp.net-corecontainerskestrel

ASP.NET Core + Docker not accessible on specified port


It is impossible for me to access container with ASP.NET Core 3.1 application running inside. Goal is to run application in container on port 5000. When I'm running it locally using standard VS profile I navigate to http://localhost:5000/swagger/index.html in order to load swaggerUI. I would like to achieve same thing using docker.

Steps to reproduce my issue:

Running commands above with specific docker file results in this:

    [21:28:42 INF] Starting host.
    [21:28:42 INF] Now listening on: http://[::]:5000
    [21:28:42 INF] Application started. Press Ctrl+C to shut down.
    [21:28:42 INF] Hosting environment: Production
    [21:28:42 INF] Content root path: /app

However, I can't access container using http://localhost:5000/swagger/index.html because of ERR_CONNECTION_REFUSED -> This site can't be reached.

I did get into container to check if host is running for sure, using:

docker exec -it containerId /bin/bash
cd /app
dotnet myapp.dll

what resulted in following error:

Unable to start Kestrel.
System.IO.IOException: Failed to bind to address http://[::]:5000: address already in use.

Conclusion is that port inside the container is used, application is alive, it's just not accessible from outside.I don't know how to get inside of it. Please point me into right direction.

UPDATE Issue is solved, answer is posted below. However explanation why it was needed and how it works would be nice!


Solution

  • To solve the issue I had to manually add "--server.urls" to entrypoint like shown below:

    ENTRYPOINT ["dotnet", "myapp.dll", "--server.urls", "https://+:5000"]