0

I'm tring to run my asp.net core wep app in docker container using official Microsoft asp.net core 2.1 image. My application uses port 5000 to expose api. This port is configured in custom section of appSettings.json

Here is docker command that i use

docker container run --rm -p 5000:5000 -v C:\Build\MyApp:/build -w /build  --name coreApp mcr.microsoft.com/dotnet/core/aspnet:2.1 dotnet MyApp.dll

Insinde container log I got the following

warn: Microsoft.AspNetCore.Server.Kestrel[0]
      Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'.
Hosting environment: Production
Content root path: /build
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

When I try to go to http://localhost:5000 I get ERR_EMPTY_RESPONSE. Seem like container does not map local port 5000 to 5000 inside the container

1 Answer 1

1

warn: Microsoft.AspNetCore.Server.Kestrel[0] Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'.

This warning is the key.

Assuming you're using .UseUrls(), try "http://0.0.0.0:5000" or "http://+:5000" in your configuration.

Sign up to request clarification or add additional context in comments.

2 Comments

Yep! changing localhost to 0.0.0.0 works. But is there any other way to let docker use localhost instead of 0.0.0.0 ?
No, as far as I know. What you certainly can do is making environment variables override file configuration settings by building your own IConfiguration using ConfigurationBuilder() and its option .AddEnvironmentVariables(); which will allow you to manage as many variables as you want. Another alternative for this scenario seems to be using ASPNETCORE_URLS env var, but I haven't tried that yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.