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.79k stars 440 forks source link

Restarting containers using docker file fails #6392

Open davidfowl opened 2 hours ago

davidfowl commented 2 hours ago
var builder = DistributedApplication.CreateBuilder(args);

var db = builder.AddMongoDB("mongo")
                .AddDatabase("db");

builder.AddDockerfile("api", "node")
       .WithHttpEndpoint(targetPort: 3000, env: "PORT")
       .WithReference(db);

builder.Build().Run();

Here's what happens: https://github.com/user-attachments/assets/04c3b6c9-78b0-4f38-a701-26eea0f39df4

Here's the console output: Image

Additional information: Stop and Start seem to work.

mitchdenny commented 2 hours ago

Just as a diagnostic (wasn't clear from the video) - but had the container started by the time you pressed Restart? I've noticed sometimes there can be a bit of a delay between the container build completing and the container actually running.

davidfowl commented 2 hours ago

It was running yep.

mitchdenny commented 2 hours ago

I'm able to repro with Stop then Start too (on main).

mitchdenny commented 1 hour ago

OK so I added some extra logging to the start/stop logic:

https://github.com/dotnet/aspire/pull/6395

What I'm seeing based on my logging changes is this output.

warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Starting delete of resource.
info: Aspire.Hosting.Dcp.dcpctrl.ContainerReconciler[0]
      no more Container resources are being watched, cancelling container watch {"Container": {"name":"mycontainer-pjuuytar"}, "Reconciliation": 20}
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Completed delete of resource.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Getting resource.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Resource got!.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Getting resource.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Resource got!.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Getting resource.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Resource got!.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Getting resource.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Resource got!.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Getting resource.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Resource got!.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Getting resource.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Resource got!. <------ it gave up trying to start here because the resource still existed.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Starting delete of resource.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Completed delete of resource.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Getting resource.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Resource got!.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Getting resource.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Resource got!.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Getting resource.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Resource not found.
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Creating
warn: Aspire.Hosting.Dcp.ApplicationExecutor[0]
      Created! <---- second time worked.

What I think is happening is that it is taking a long time for Docker to stop the container (or for DCP to notice).

mitchdenny commented 1 hour ago

@danegsta could use your input on this one. @davidfowl if you checkout my branch from the PR above do you see similar symptoms. I'm particularly interested in the time it takes between pressing Stop and for it to appear stopped in the portal.

It's possible I've got some local performance issues, but I haven't done much exotic to my machine other than keep up with updates.