Restart Policies

When your containers exits, you can use restart policies to automatically restart it.
You can use this to create containers that will start automatically when you computer restarts.

Restart Policies

Here are the basics:

  • --restart no
    means that docker will never restart your container.
  • restart on-failure[:max-retries]
    means that it will be restarted only if it failed (and optionally a limited number of retries)
  • restart always
    means that it will always be restarted:
    • if manually stopped, then only after docker daemon restart (e.g on computer restart)
    • otherwise restart immediately
  • restart unless-stopped
    means that it will be restarted in any case (boot, failure etc.) unless it was manually stop.

Use with --rm option

  • The --rm options for docker run automatically removed the stopped container left after the container has exited.
  • It makes no sense to remove this container if you intend to restart it.
  • This is why --rm conflicts with --restard for all restart policies except --restart no