---
title: The container should have a restart policy limited to 5 attempts
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > OOTB Rules > The container should have a restart
  policy limited to 5 attempts
---

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

# The container should have a restart policy limited to 5 attempts
Classification:complianceFramework:cis-dockerControl:5.15 
## Description{% #description %}

A container restarted on failure should stop after at most five attempts.

## Rationale{% #rationale %}

A container that always restarts can loop forever on a fault and load the host. The `on-failure` policy with a limit, or no restart policy, keeps the attempts bounded.

## Audit{% #audit %}

Inspect the containers:

```bash
docker ps --quiet --all | xargs docker inspect --format '{{ .Name }}: RestartPolicyName={{ .HostConfig.RestartPolicy.Name }} MaximumRetryCount={{ .HostConfig.RestartPolicy.MaximumRetryCount }}'
```

Datadog passes the rule when a container has no restart policy, or `on-failure` with 1 to 5 attempts, and fails it for `always`, `unless-stopped`, and `on-failure` without a limit or with more than 5.

## Remediation{% #remediation %}

Run the container with a bounded policy:

```bash
docker run --restart=on-failure:5 <image>
```

## Impact{% #impact %}

A container that fails more often stays stopped until someone restarts it.

## Default value{% #default-value %}

The restart policy of a container is `no`.

## References{% #references %}

1. [https://docs.docker.com/reference/cli/docker/container/run/#restart-policies—restart](https://docs.docker.com/reference/cli/docker/container/run/#restart-policies---restart)
