Search code examples
restartpolicyamazon-ecs

AWS ECS Restart Policy


I've inspected one of the docker containers I have running in my ECS cluster and it has a blank for the restart policy ("{{ .HostConfig.RestartPolicy.Name }}"). I'm unsure what ECS does in the case of a failure but I would like to change the policy to one that restarts the container instance if the cmd running in the instance fails. Is it possible to change the restart policy on docker containers in an ECS cluster?


Solution

  • Is it possible to change the restart policy on docker containers in an ECS cluster?

    No, ECS does not support restarting existing containers. However, please see below for further details.

    I'm unsure what ECS does in the case of a failure

    For a single task (started by the RunTask or StartTask APIs), ECS will do nothing in the case of a container stopping except report the stop (exit code and reason, if known) through the DescribeTasks API call and through CloudWatch Events.

    I would like to change the policy to one that restarts the container instance if the cmd running in the instance fails.

    ECS supports this use-case through the concept of a "service". Services work to continuously make the reality (known state) match the desired state, including the desired number of running tasks you specify. If a task started by a service stops, the service will create a new task to replace it. Services help you manage the number of copies you want running, deployments, binding to and unbinding from load balancers, respond to load balancer health checks, and integrate with auto scaling so your service can scale in or out automatically. You can check out the documentation for more detail.