---
title: On-failure restart count is unbounded or excessive
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Infrastructure as Code (IaC)
  Security > IaC Security Rules > On-failure restart count is unbounded or
  excessive
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# On-failure restart count is unbounded or excessive

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**Id:** `dockercompose-on-failure-restart-count-unbounded-or-excessive` 

**Platform:** DockerCompose

**Severity:** Medium

**Category:** Availability

#### Learn More{% #learn-more %}

- [Provider Reference](https://docs.docker.com/reference/compose-file/services/#restart)

### Description{% #description %}

An unbounded `on-failure` restart policy can cause containers to restart indefinitely after repeated failures, masking the root cause, consuming system resources in a crash loop, and destabilizing the host. For service-level restart policies using `restart: on-failure`, a maximum retry count should be appended (e.g., `on-failure:5`) and must not exceed five. For `deploy.restart_policy` with `condition: on-failure`, the `max_attempts` field must be defined and set to a value between one and five.

## Compliant Code Examples{% #compliant-code-examples %}

```yaml
services:
  one:
    image: alpine
    restart: on-failure:1
  five:
    image: alpine
    restart: on-failure:5
  always:
    image: alpine
    restart: always
  deploy_precedence:
    image: alpine
    restart: on-failure
    deploy:
      restart_policy:
        condition: on-failure
        max_attempts: 5
```

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```yaml
services:
  unbounded:
    image: alpine
    restart: on-failure
  excessive:
    image: alpine
    restart: on-failure:6
  deploy_unbounded:
    image: alpine
    restart: on-failure:2
    deploy:
      restart_policy:
        condition: on-failure
  deploy_excessive:
    image: alpine
    deploy:
      restart_policy:
        condition: on-failure
        max_attempts: 7
```
