5

I have a container that is part of an ECS task definition, which I have marked as essential=false, because if this container goes down, I do not want the ECS agent to take down the other containers in the task. Making the container "non-essential" has achieved the desired result in my case: that container crashes, and the other containers on the task do not get taken down or restarted.

However, I do want this non-essential container to be independently restarted. Is there any built-in way to accomplish this? Basically, if the container exits, run docker start or docker restart on that container (which we are currently having to do manually). I have not had any luck so far with the documentation or from exploring the AWS console.

elethan
  • 16,408
  • 8
  • 64
  • 87
  • Are you / Have you tried running the container as part of an ECS service? If this container can crash and not have an impact on the others in your task, can you run it as a separate task? – arco444 Aug 30 '18 at 10:50
  • have you tried other container image with hypervisord ? Hypervisord allows you to restart, container process if it's crashed and ensures container is running.. So, with hypervisord container will not exit.. your app will be restarted by hpervisord if it crashes.. – Ankush T Aug 31 '18 at 10:16
  • @arco444 good idea! This would require some changes that our team won't be able to make at the moment, but this sounds like a really promising option. I will update here if we implement this. Thanks! – elethan Sep 04 '18 at 13:36
  • @AnkushTehale interesting idea! I will look into this. Thanks! – elethan Sep 04 '18 at 13:37
  • Did the answer below helped you? Thanks! – Fabio Manzano Sep 04 '18 at 19:25
  • 1
    @elethan did you solve your issue by converting to Services? I am also experiencing this issue, and my reason for having multiple Containers under one task definition is to communicate between the containers within the Cluster. – fuzzi Oct 24 '18 at 01:58
  • @fuzzi sorry, I haven't made any progress on this. Priority has shift at my work, and this has been put on hold :( – elethan Oct 30 '18 at 18:36

1 Answers1

3

Docker provides a restart policy that would be useful in your case (--restart always), however, based on this thread, ECS does not support restarting existing containers.

The suggested and accepted workaround was:

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.

Fabio Manzano
  • 2,847
  • 1
  • 11
  • 23
  • I will look into this. I know we do some configuration with user data already. Do you have any more specific suggestions as to how user data could be used to restart an exited container? – elethan Sep 04 '18 at 19:38
  • 1
    @elethan, I was wondering if you could set [Docker restart policy](https://docs.docker.com/config/containers/start-containers-automatically/) through user-data: --restart always. However, it doesn't seems to be supported by ECS, as discussed in [this thread](https://stackoverflow.com/questions/46226882/aws-ecs-restart-policy). I'll update the answer with the findings. – Fabio Manzano Sep 04 '18 at 19:57
  • Thanks Fabio! I won't be able to test this solution for a little while because: crunch time at work. But this info is helpful so I gave you a +1! I'll update once/if I try this out! – elethan Sep 06 '18 at 13:15