This product is not supported for your selected Datadog site. ().

Metadata

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

Platform: DockerCompose

Severity: Medium

Category: Availability

Learn More

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

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

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