For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/default_rules/69v-npt-bzr.md. A documentation index is available at /llms.txt.

The container should have a restart policy limited to 5 attempts

docker

Classification:

compliance

Framework:

cis-docker

Control:

5.15

Description

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

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

Inspect the containers:

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

Run the container with a bounded policy:

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

Impact

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

Default value

The restart policy of a container is no.

References

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