Learning center

ECS dependsOn condition never met: init, sidecar or app container?

Read each container's exit code and health status beside the revision's dependsOn graph to find the container that broke the chain. An app container with no exit code was held back by a dependency; one with an exit code ran and failed by itself.

How a dependency holds a container back#

A task definition can make one container wait for another with dependsOn, naming a container and a condition. If the condition is not met, or times out first, ECS does not move the waiting container to its next state, so it never starts. The task then never reaches RUNNING with its app. ContainerDependency · Container dependency parameters

ConditionThe waiting container starts when the named containerHow it is never met
STARTHas startedThe named container cannot be created or started
COMPLETEHas exited, with any exit codeThe named container keeps running
SUCCESSHas exited with exit code 0It exits non-zero, or keeps running
HEALTHYPasses the health check in its container definitionIt has no healthCheck in the revision, or its check keeps failing

Two documented rules matter most for init containers. COMPLETE and SUCCESS can't be set on an essential container, and a container whose essential field is omitted counts as essential. When an essential container stops for any reason, ECS stops every other container in the task. ContainerDefinition essential

HEALTHY has a trap of its own. ECS monitors only health checks declared in the container definition. A HEALTHCHECK built into the image's Dockerfile is not monitored, and a container with no declared check reports UNKNOWN, which never becomes HEALTHY. HealthCheck · Container health status

startTimeout bounds the wait. In AWS's example, container A depends on container B reaching COMPLETE, SUCCESS or HEALTHY, and a startTimeout set on B makes A give up when B misses that status in time; the task then moves to STOPPED. On Fargate the valid values are 2 to 120 seconds. On EC2, the agent's ECS_CONTAINER_START_TIMEOUT setting is enforced independently. startTimeout

Read the graph and the containers#

Use a read-only profile and replace the uppercase placeholders. First the revision's graph, with the fields that decide each edge:

aws ecs describe-task-definition \
  --profile PROFILE --region REGION --task-definition TASK_DEFINITION_ARN \
  --query 'taskDefinition.containerDefinitions[].{name:name,essential:essential,dependsOn:dependsOn,startTimeout:startTimeout,healthCheck:healthCheck.command,command:command}' \
  --output json --no-cli-pager

If essential shows null, the field was omitted, and the container counts as essential. Then the stopped task, container by container. ECS keeps stopped tasks for at least one hour. Task fields · Stopped task retention

aws ecs describe-tasks \
  --profile PROFILE --region REGION --cluster CLUSTER --tasks TASK_ARN \
  --query 'tasks[].{definition:taskDefinitionArn,code:stopCode,reason:stoppedReason,started:startedAt,stopped:stoppedAt,containers:containers[].{name:name,status:lastStatus,exit:exitCode,reason:reason,health:healthStatus}}' \
  --output json --no-cli-pager

Walk the graph from the app container back through its dependencies. The first container on that path that exited non-zero, never turned healthy, or stayed running when it was meant to finish is the one to fix. Read its own logs and reason; the waiting containers have none.

What each pattern means#

Dependency containerApp containerReadingChange
Init container with SUCCESS, exit code non-zeroNo exit codeThe init step failed; the app was never allowed to startFix the init step; its logs hold the error
Init container with COMPLETE or SUCCESS, still running when the task stoppedNo exit codeThe init step did not finish within startTimeoutFind out why it hangs, or give it a longer startTimeout
Sidecar with HEALTHY, health UNKNOWN, no healthCheck in the revisionNo exit codeThe condition can never be metDeclare a healthCheck in the sidecar's container definition
Sidecar with HEALTHY, health UNHEALTHYNo exit codeThe sidecar's own check failsRead the sidecar's logs and its check command
Init container used with START and left essential, exit code 0StoppedThe init container's normal exit stopped the taskSet essential to false and use SUCCESS
Every dependency met: exit code 0 or HEALTHYExit code setThe app ran and failed by itselfTreat it as a process exit; the app's logs are the next read

If a dependency container never started at all and its own reason begins CannotStartContainerError, the command or image is the problem, which the command-not-found guide covers. For the last row, the stop code is usually EssentialContainerExited, and the stop code guide sorts what follows.

Two ways orders:63 can fail#

This fixture is illustrative. The fictional service orders moves to orders:63, which adds two containers in front of app: migrate, an init container with essential set to false that app waits on with SUCCESS, and proxy, a sidecar that app waits on with HEALTHY. proxy has a startTimeout of 120 seconds.

ContainerInit failureHealth check missing
migrateExit code 1Exit code 0
proxyRunning, health HEALTHYRunning, health UNKNOWN; the revision has no healthCheck, the image has a Dockerfile HEALTHCHECK
appNo exit codeNo exit code
TaskNever reached RUNNINGStopped about two minutes after proxy started

In the first case the graph stopped at migrate. Its log shows the failure, and app was correct to wait. Fix the migration and redeploy; nothing about app changed. In the second case migrate succeeded and proxy was running, but ECS had no declared check to evaluate, so proxy stayed UNKNOWN until its startTimeout ran out. The image's own HEALTHCHECK does not count. Copy the check into proxy's container definition as healthCheck.

Had app shown exit code 1 with migrate at 0 and proxy HEALTHY, the dependencies would be cleared and the app itself would be the failure.

Confirm on the replacement task#

On the replacement, read the same container query. Each dependency should show the state its condition asks for: exit code 0 for SUCCESS, an exit code for COMPLETE, HEALTHY for HEALTHY. The app container should be running with no exit code, and the task should have a startedAt. If the service has a load balancer, its target health is the next read once the task runs.

Where this reading stops#

None of the seven stop codes is specific to an unmet dependency, so the container records are the evidence. Two conditions are weaker than they look. START waits only for the named container to start, so an app that needs an init step to finish can start too early and fail by itself; use SUCCESS for that. HEALTHY is checked only at task startup, so a sidecar that turns unhealthy later does not hold anything back. ContainerDependency

Container dependencies need ECS agent 1.26.0 or later on EC2, and Linux platform version 1.3.0 or later, or Windows platform version 1.0.0 or later, on Fargate. Dependencies also reverse at shutdown, so the app container stops before the containers it depends on. ContainerDependency

This guide is one of the ordering rows in the signature table.

Questions#

Why does my ECS app container never start when it depends on another container?

ECS does not start a container until each dependsOn condition is met. Check the named container: a non-zero exit fails SUCCESS, a container that keeps running never meets COMPLETE, and a container with no declared health check never becomes HEALTHY.

Does ECS use the HEALTHCHECK from my Docker image for a HEALTHY dependency?

No. ECS monitors only the healthCheck in the container definition, and reports UNKNOWN for a container without one. Declare the check in the task definition.

Should an init container be marked essential?

No. COMPLETE and SUCCESS can't be set on an essential container, and an essential container that exits stops the whole task. Set essential to false and have the app wait on it with SUCCESS.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading