简体   繁体   中英

Depends on Fargate ECS

I have container A this container holds my broker service that delivers messages and creates a socket that my other services connect to and then send messages to.

I have an issue where container A has to be running before containers B and C or they are unable to connect to the socket.

In ECS / Fargate is it possible to tell containers B and C to restart if container A goes down or if container A is restarted to tell B and C to redeploy so the application is spun up again and it can successfully connect to the socket.

In docker-compose I can use depends_on within the setup, Is there something similar for ECS / Fargate?

I have tried adding

   "dependsOn": [
        {
            "containerName" : "containerA",
            "condition" : "HEALTHY"
        }
    ]

To my task definition but it complains it can't find the container. My containers are all in separate task definitions in separate services.

Yes, there is a similar feature in AWS ECS called Container Dependency .

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

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html#container_definition_dependson

The dependencies defined for container startup and shutdown. A container can contain multiple dependencies. When a dependency is defined for container startup, for container shutdown it is reversed.

If your containers are on separated tasks, I suggest the following way to work around:

For example you got container-A in task-A and container-B in task-B, and you need to run container-B when container-A is available.

  1. Expose a health check of container-A. For example: :8081/health
  2. Create container-C in task-B. This container will try to ping to container-A via health check until success.
  3. container-B will depend on container-C to start.

Just the idea. Thank you for reading.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM