1
votes

I'm following a https://app.pluralsight.com/library/courses/docker-web-development/table-of-contents which uses the older microsoft/aspnetcore-build image but I'm running core 2.1 so I'm using microsoft/dotnet:2.1-sdk instead.

The command I'm running is:

docker run -it -p 8080:5001 -v ${pwd}:/app -w "/app" microsoft/dotnet:2.1-sdk

and then once inside the TTY I do a dotnet run which gives me the following output:

Using launch settings from /app/Properties/launchSettings.json...

info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]

User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.

info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[58]

Creating key {5445e854-c1d9-4261-82f4-0fc3a7543e0a} with creation date 2018-12-14 10:41:13Z, activation date 2018-12-14 10:41:13Z, and expiration date 2019-03-14 10:41:13Z.

warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]

No XML encryptor configured. Key {5445e854-c1d9-4261-82f4-0fc3a7543e0a} may be persisted to storage in unencrypted form.

info: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[39]

Writing data to file '/root/.aspnet/DataProtection-Keys/key-5445e854-c1d9-4261-82f4-0fc3a7543e0a.xml'.

warn: Microsoft.AspNetCore.Server.Kestrel[0]

Unable to bind to https://localhost:5001 on the IPv6 loopback interface: 'Cannot assign requested address'.

warn: Microsoft.AspNetCore.Server.Kestrel[0]

Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'.

Hosting environment: Development

Content root path: /app

Now listening on: https://localhost:5001

Now listening on: http://localhost:5000

Application started. Press Ctrl+C to shut down.

Then, when I open browser on my host and navigate to http://localhost:8080 I get a "This page isn't working" "localhost didn't send any data" " ERR_EMPTY_RESPONSE"

I've tried a couple different port combinations too with the same result.

Can anyone spot where I went wrong? Or have any ideas / suggestions?

1
did you try to hit https endpoint: localhost:8080 ?Michael
You are mapping 8080:5001 which is https port, you need to access https as the suggestion from Michael. If not work, can you share us detail steps to reproduce your issue? It seems to be related with the error unable to bind to 5001. Have you launch multiple apps? Try to change a new port like 5002.Edward
@Michael Yeah i did - same thingStark
@TaoZhou Im actually mapping to both http(5000) and http(5001). Have tried both http and https, slightly different effect, this time getting ERR_CONNECTION_CLOSED. Also tried it on port 8082Stark
Is there any demo and detail steps to reproduce your issue?Edward

1 Answers

3
votes

Not sure if this question still relevant for you, but I also encountered this issue and left my solution here for others. I used PowerShell with the next docker command (almost the same as your command, just used internal port 90 instead of 5000 and used --rm switch which will automatically remove the container when it exits):

docker run --rm -it -p 8080:90 -v ${pwd}:/app -w "/app" microsoft/dotnet /bin/bash

And after that, I got the interactive bash shell, and when typing dotnet run I got the same output as you and cannot reach my site in the container via localhost:8080.

I resolved it by using UseUrls method or --urls command-line argument. They (UseUrls method or --urls command-line argument) indicates the IP addresses or host addresses with ports and protocols that the server should listen on for requests. Below descriptions of solutions which worked for me:

  1. Edit CreateWebHostBuildermethod in Program.cs like below:
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
                WebHost.CreateDefaultBuilder(args)
                   .UseUrls("http://+:90") //for your case you should use 5000 instead of 90
                    .UseStartup<Startup>();

You can specify several ports if needed using the next syntax .UseUrls("http://+:90;http://+:5000")
With this approach, you just typed dotnet run in bash shell and then your container will be reachable with localhost:8080.

  1. But with the previous approach you alter the default behavior of your source code, which you can forget and then maybe should debug and fix in the future.
    So I prefer 2nd approach without changing the source code. After typing docker command and getting an interactive bash shell instead of just dotnet run type it with --urls argument like below (in your case use port 5000 instead of 90):

    dotnet run --urls="http://+:90"

  2. In the documentation there is also a 3rd approach where you can use ASPNETCORE_URLS environment variable, but this approach didn't work for me. I used the next command (with -e switch):

docker run --rm -it -p 8080:90 -v ${pwd}:/app -w "/app" -e "ASPNETCORE_URLS=http://+:90" microsoft/dotnet /bin/bash

If you type printenv in bash you will see that ASPNETCORE_URLS environment variable was passed to the container, but for some reason dotnet run is ignoring it.