# RestartPolicy Properties

- Package: [Aspire.Hosting.Docker](/reference/api/csharp/aspire.hosting.docker.md)
- Type: [RestartPolicy](/reference/api/csharp/aspire.hosting.docker/restartpolicy.md)
- Kind: `Properties`
- Members: `4`

Defines the restart policy for a Docker service in a Swarm cluster.

## Condition

- Name: `Condition`
- Modifiers: `nullable` `get; set`
- Returns: `string?`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Docker/Resources/ServiceNodes/Swarm/RestartPolicy.cs)

Specifies the condition under which a service's container will be restarted.

```csharp
public string? Condition { get; set; }
```

## Remarks

This property determines the criteria for restarting a container. Possible values may include "none", "on-failure", or "any", which dictate when a restart should happen (e.g., never, only on failures, or always).

## Delay

- Name: `Delay`
- Modifiers: `nullable` `get; set`
- Returns: `string?`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Docker/Resources/ServiceNodes/Swarm/RestartPolicy.cs)

Specifies the delay duration between restart attempts of the service container.

```csharp
public string? Delay { get; set; }
```

## Remarks

The delay defines the time interval to wait before attempting to restart a service container after a failure. It is expressed as a time duration string (e.g., "5s" for 5 seconds).

## MaxAttempts

- Name: `MaxAttempts`
- Modifiers: `nullable` `get; set`
- Returns: `int?`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Docker/Resources/ServiceNodes/Swarm/RestartPolicy.cs)

Specifies the maximum number of restart attempts allowed for a container as part of the restart policy.

```csharp
public int? MaxAttempts { get; set; }
```

## Remarks

Defines the upper limit for how many times Docker will attempt to restart the container before giving up. If not set, the system default behavior or an unlimited restart attempts policy may be applied. This setting is useful for handling scenarios where a service is repeatedly failing and prevents infinite restart loops.

## Window

- Name: `Window`
- Modifiers: `nullable` `get; set`
- Returns: `string?`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Docker/Resources/ServiceNodes/Swarm/RestartPolicy.cs)

Defines the time window for evaluating the restart conditions in a Docker service restart policy.

```csharp
public string? Window { get; set; }
```

## Remarks

This property specifies the duration (e.g., in seconds or any supported time format) during which restart attempts are counted towards the maximum attempts allowed. If the service exits and restarts within this specified window, it contributes to the count of restart attempts under the restart policy.
