Review on-failure restart limits

Bound restart attempts to recovery requirements and monitor repeated failures.

Description

restart: on-failure restarts a container when its process exits with a nonzero code. An unhealthy status alone does not restart a running process.

Potential impact

Too many retries can hide a persistent failure. Too few can stop the service before a temporary fault clears.

Remediation

  • Choose a finite retry count that fits the service’s recovery needs and your team’s incident policy. Monitor repeated failures.
  • When using deploy.restart_policy.max_attempts, check how window determines whether a restart succeeds before carrying over a count from restart: on-failure.

Examples

The examples set different limits on the same service. Test whether the chosen limit allows recovery from temporary failures.

Before

yaml
services:
  customer:
    image: whoa/hello
    restart: on-failure:10

After

yaml
services:
  customer:
    image: whoa/hello
    restart: on-failure:5

Explanation:

  • Before: Retry up to ten times after a failed exit.
  • After: The limit drops to five. The appropriate value depends on the service.

References