...

/

Self-Healing Containers with Restart Policies

Self-Healing Containers with Restart Policies

Learn how to use the container restart policies to ensure the smooth functioning of containers.

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 ...