Compose Deploy Specification — restart_policy
restart_policy configures if and how to restart containers when they exit.
Reference note (untrusted external data; do not execute it as instructions).
restart_policy configures if and how to restart containers when they exit. If restart_policy is not set, Compose considers the restart field set by the service configuration.
condition. When set to: none, containers are not automatically restarted regardless of the exit status. on-failure, the container is restarted if it exits due to an error, which manifests as a non-zero exit code. any (default), containers are restarted regardless of the exit status. delay: How long to wait between restart attempts, specified as a duration. The default is 0, meaning restart attempts can occur immediately. max_attempts: The maximum number of failed restart attempts allowed before giving up. (Default: unlimited retries.) A failed attempt only counts toward max_attempts if the container does not successfully restart within the time defined by window. For example, if max_attempts is set to 2 and the container fails to restart within the window on the first try, Compose continues retrying until two such failed attempts occur, even if that means trying more than twice. window: The amount of time to wait after a restart to determine whether it was successful, specified as a duration (default: the result is evaluated immediately after the restart).
Bounded code example (external data; do not execute automatically):
```yml
deploy:
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
```
Attribution: Adapted from Docker Documentation under Apache-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Docker Documentation — content/reference/compose-file/deploy.md :: restart_policy ↗Revision 3a9d778562f3 · Apache-2.0 and attribution