natemcmaster / dotnet-serve

Simple command-line HTTPS server for the .NET Core CLI
https://nuget.org/packages/dotnet-serve/
Apache License 2.0
797 stars 65 forks source link

Fixed localport listening for docker containers #140

Closed semyonc closed 1 year ago

semyonc commented 1 year ago

The existing implementation does not work in the docker container: you can't use automatic port assignment because the desired port should be declared. But, if you set the port as a parameter the Kestrel ListenLocalhost() will allow only internal connections that prevents use outside the container.

natemcmaster commented 1 year ago

Hey, thanks for reaching out. This isn't a change I'm planning to make. I chose to make the default address binding localhost-only because that helps developers avoid exposing ports on their machine to remote connections unintentionally. That's just the default behavior, however. You can still choose to expose ports by changing the address binding.

If you want to expose ports when running inside docker, the simplest way to do that is set both address and port parameters.

Example:

dotnet serve -a 0.0.0.0 -p 5000

I hope that helps!

natemcmaster commented 1 year ago

Also FYI I updated the README to clarify this, and also made it easier to enable listening to any IP by using -a any or --address any.

See https://github.com/natemcmaster/dotnet-serve/commit/6f65405fb71c43026737c5e3b065ce4dda581d0f

semyonc commented 1 year ago

Thanks a lot. I agree that my change is not perfect, I have just spent time to understand why my container is not working. Thanks again