dotnet / aspire

An opinionated, cloud ready stack for building observable, production ready, distributed applications in .NET
https://learn.microsoft.com/dotnet/aspire
MIT License
3.65k stars 416 forks source link

Dynamic port allocation not supported for containers #4559

Open davidfowl opened 3 months ago

davidfowl commented 3 months ago
var builder = DistributedApplication.CreateBuilder(args);

builder.AddDockerfile("app", "nodeapp")
       .WithHttpEndpoint(env: "PORT");

builder.Build().Run();

@karolz-ms can we support dynamic port allocation for containers as well?

karolz-ms commented 3 months ago

We could. This wasn't deemed a priority because, typically, the program that is running inside a container is the only game in town, and it can choose whatever port is convenient and stick to it, as long as the container image allows for using that port.

Note that by default Aspire-orchestrated containers are proxied by container orchestrator and by DCP, and from the client perspective, the ports that clients use to communicate with these containers are dynamic, unless fixed by app model.

What is the motivation behind this idea?

davidfowl commented 3 months ago

Now that we have docker file building it’ll be possible to build experiences where you can flip between docker and local, and it would be ideal if you didn’t have to change endpoint configuration as a result.

karolz-ms commented 3 months ago

OK I buy that. We would have to make some assumptions about the range of ports that we could use for dynamic port allocation, but overall this should not be too hard to do.