Search⌘ K
AI Features

Self-Healing Containers with Restart Policies

Explore how Docker restart policies provide self-healing capabilities to containers by automatically restarting them after failure or exit. Understand the four main restart policies, their effects, and practical usage through examples. Gain skills to enhance container reliability and lifecycle management in Docker environments.

Container restart policies are a simple form of self-healing that allows the local Docker Engine to automatically restart failed containers.

Restart policies

We apply restart policies per container, and Docker supports the following four policies:

  • no (default)
  • on-failure
  • always
  • unless-stopped

The following table shows how each policy reacts to different scenarios. A “Y” indicates the policy will attempt a container restart, whereas an “N” indicates it won’t.

Restart Policy

Non-Zero Exit Code

Zero Exit Code

The docker stop Command

Restarts When Daemon Restarts

No

N

N

N

N

On-Failure

Y

N

N

Y

Always

Y

Y

N

Y

Unless-Stopped

Y

Y

N

N

Non-zero exit codes indicate a failure occurred. Zero exit ...