Don't restart container if exit code was `0` and `WithLifetime` is set to persistent
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
I have an stack built with:
- Some persistent database container, like PostgreSQL
- Some persistent queue container, like RabbitMQ
- Another team's container
- Another team's container migrating the database (one-time cli app)
- My application
etc...
After updating to Aspire 9.3 (https://github.com/dotnet/aspire/pull/8477), the CLI application displays **Exited** upon completion, what is great.

But when I mark CLI lifetime as persistent, anyway every time I start the AppHost, the cli in container starts again.
I have a suggestion that if I have consciously marked these applications as persistent, and Aspire knows that they correctly Exited with code 0, then do not restart them on the next attempt.
### Describe the solution you'd like
If a container has gracefully exited and has been marked persistent, do not restart it when restarting AppHost.
### Additional context
https://github.com/dotnet/aspire/issues/4366
https://github.com/dotnet/aspire/issues/6785
https://github.com/dotnet/aspire/pull/8477
Contributor guide
Research direction
No file or test is named in the issue. Start by tracing Aspire's persistent container lifetime and AppHost restart handling, including the behavior for containers that exit with code 0. Done means a gracefully exited persistent container is not restarted on the next AppHost start, while other containers retain their existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, docker
- Domain
- devops, infrastructure
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100