Search code examples
dockerdockerfileamazon-ecs

Restart containers within ECS when a certain container is deployed


I have a project that runs multiple GO services using ECS. For example, I have 3 containers, A, B, C, and then container D holds config and stuff for the other containers. Is there a way that when container D is updated or restarted I can then restart the other containers within ECS so they can use the new data from container D?

I was thinking of having a pub/sub type thing and telling the other containers a new version had been released but I was thinking there must be an easier way that doesn't involve any extra code.

I'd also like to do this for my local docker-compose stack if possible.


Solution

  • After a bit of searching, I found you can add container dependencies within the task definition JSON.

    https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDependency.html

    This allows you to add dependencies for the different containers running.

    For example:

      "containerDefinitions": [
        {
          "name": "app",
          "image": "application_image",
          "portMappings": [
            {
              "containerPort": 9080,
              "hostPort": 9080,
              "protocol": "tcp"
            }
          ],
          "essential": true,
          "dependsOn": [
            {
              "containerName": "container-a",
              "condition": "HEALTHY"
            }
          ]
        },
    

    Very useful.