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

Docker container Restart Policy #5003

Open urumo opened 1 month ago

urumo commented 1 month ago

Background and Motivation

I have a containerised go application which connects to a websocket service and because of that might fail every once in a while, this is why I need an option to specify the restart policy for any and all containers in the project.

Proposed API

IResourceBuilder<ContainerResource>.WithRestart(RestartPolicy)

Usage Examples

var builder = DistributedApplication.CreateBuilder(args);

var catalogDb = builder.AddMySql("mysql").WithRestart(RestartPolicy.OnFailure);

Risks

The container might end up in a restart loop if the it is faulty and will need to be killed from the shell.

Implementation

A draft PR with implementation is #5001

davidfowl commented 1 week ago

Thoughts @mitchdenny @DamianEdwards @karolz-ms ?

mitchdenny commented 1 week ago

I think it would be good to have this. I'm not sure about IResourceWithRestartPolicy vs just having an annotation.

DamianEdwards commented 1 week ago

I'm assuming this is intended to be run mode only? I still have some concern over the proliferation of "unbounded" With methods where it isn't clear what they apply to, e.g. WithRestartPolicy vs. RunWithRestartPolicy.

karolz-ms commented 1 week ago

If we are talking about local run only, one can work around the lack of restart support today by using WithContainerRunArgs() and --restart Docker option (which Podman also supports).

Going forward I think we should revisit this once we have health checks in place. "Restart when unhealthy" (after some time, after health probe(s) fail N times) seems more useful than any existing Docker/Podman restart mode.

I also have a concern about target environment (local run, vs Azure Container Apps, vs vanilla Kubernetes, vs...) supporting different functionality for automatic restarts. If we decide to add a restart notion to the app model, I'd love it to be applicable not just to local run, but to deployment environments too, but we need to be able to account for different level of restart support between them.