jschuss
jschuss

Reputation: 655

AWS ECS Updating service wipes mongo container

I have a node/mongo app deployed using ECS. The running task contains two containers, one for my node api, and another for my mongo database. When I push changes I make to my api and create a new task revision + update my service using it, it deploys the changes, but wipes my database clean every time.

  1. With this setup, is updating a service always going to deploy a new mongo container?
  2. Any chance I could revert to the previous state of that service?
  3. Would it be better to create a separate task for each container

Any help would be greatly appreciated

Upvotes: 0

Views: 173

Answers (1)

Adiii
Adiii

Reputation: 60074

  1. yes, it will always deploy a new container from the image that is mentioned in the task definition.

    When UpdateService stops a task during a deployment, the equivalent of docker stop is issued to the containers running in the task. This results in a SIGTERM and a 30-second timeout.

update-service

  1. No, When service updated it automatically remove the old container and image. because By default, the Amazon ECS container agent automatically cleans up stopped tasks and Docker images that are not being used by any tasks on your container instances.

You can control this behaviour using ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION

This variable specifies the time to wait before removing any containers that belong to stopped tasks. The image cleanup process cannot delete an image as long as there is a container that references it. After images are not referenced by any containers (either stopped or running), then the image becomes a candidate for cleanup. By default, this parameter is set to 3 hours but you can reduce this period to as low as 1 minute, if you need to for your application.

  1. Yes, It would be better to have a separate task definition. Also, I would recommend mounting in the DB container to avoid such losses in future.

AWS ecs docker-volumes

Upvotes: 2

Related Questions