description | keywords | redirect_from | title | |
---|---|---|---|---|
Automatically restart a container in Docker Cloud |
container, restart, automated |
|
Restart a container automatically |
Autorestart is a service-level setting that can automatically start your containers if they stop or crash. You can use this setting as an automatic crash recovery mechanism.
Autorestart uses Docker's --autorestart
flag. When called, the Docker daemon
attempts to restart the container until it succeeds. If the first restart
attempts fail, the daemon continues to attempt a restart, but uses an
incremental back-off algorithm.
The following Autorestart options are available:
OFF
: the container will not be restarted, regardless of the exit code.ON_FAILURE
: the container will be restarted only if it stops with an exit code other than 0. (0 is for normal shutdown.)ALWAYS
: the container will be restarted automatically, regardless of the exit code.
Note: If you are using Autorestart set to
ALWAYS
, Autodestroy must be set toOFF
.
If the Docker daemon in a node restarts (because it was upgraded, or because the
underlying node was restarted), the daemon will only restart containers that
have Autorestart set to ALWAYS
.
You can enable Autorestart on the Service configuration step of the Launch new service wizard.
Autorestart is set to OFF
by default, which means that autorestart is deactivated.
You can set the Autorestart option when launching a service through the
API and through the CLI. Autorestart is set to OFF
by default.
POST /api/app/v1/service/ HTTP/1.1
{
"autorestart": "ON_FAILURE",
[...]
}
$ docker-cloud service run --autorestart ON_FAILURE [...]
See our API documentation for more information.
You can activate or deactivate Autorestart on a service after it has been deployed by editing the service.
- Go to the service detail page.
- Click Edit.
- Choose the autorestart option to apply.
- Click Save.
You can change the Autorestart setting after the service has been deployed using the API or CLI.
PATCH /api/app/v1/service/(uuid)/ HTTP/1.1
{
"autorestart": "ALWAYS",
}
$ docker-cloud service set --autorestart ALWAYS (name or uuid)
See the API documentation for more information.