5.2.1 Configuring How Docker Restarts Containers

To specify how you want Docker to handle a container when it exits, you can use the --restart option with docker run and docker create:

--restart=always

Docker always attempts to restart the container when the container exits.

--restart=no

Docker does not attempt to restart the container when the container exits. This is the default policy.

--restart=on-failure[:max-retry]

Docker attempts to restarts the container if the container returns a non-zero exit code. You can optionally specify the maximum number of times that Docker will try to restart the container.