---
title: "ECS task failed container health checks after a deploy | Proofline"
description: "When ECS replaces tasks for failed container health checks, read each container's healthStatus and the revision's healthCheck before target health."
url: https://proofline.sh/learn/ecs-container-health-check-unhealthy/
---

[Learning center](/learn/)

# ECS task failed container health checks after a deploy

When ECS replaces tasks for failed container health checks, read each container's healthStatus and the revision's healthCheck before target health. The container health check is a command ECS runs inside the container, separate from the load balancer's check, and a release can break the command, its timing or the process it probes.

Deployment failures The Proofline team November 22, 2026 6 min read

## The signature and its nearby causes

After a deploy, new tasks reach `RUNNING`, stay up for a minute or two, and stop. The stopped reason says the task failed container health checks, and the stop code shows the scheduler stopped it. For a task that is part of a service, an `UNHEALTHY` task is stopped and the service scheduler replaces it. [HealthCheck](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_HealthCheck.html) · [The signature table](/learn/aws-deployment-failure-signatures/)

Three nearby causes look similar from the deployment's point of view:

-   **The container health check failed.** The command in the container definition's `healthCheck` returned non-zero, or timed out, enough times in a row. The target group may show the task healthy the whole time.
-   **The load balancer's health check failed.** The stopped reason names ELB health checks instead, and `describe-target-health` holds the reason code. Another guide covers those reason codes.
-   **The process exited.** The stop code is `EssentialContainerExited`, and the [exit code guide](/learn/ecs-exit-codes-after-deploy/) applies.

## Read health per container

The task's `healthStatus` is derived from its essential containers: `UNHEALTHY` if any essential container is unhealthy, `UNKNOWN` if any is unknown and none unhealthy, `HEALTHY` only if all pass. A container with no health check in its definition reports `UNKNOWN`. Read the task and each container, and do it while the replacement loop is still running, since stopped tasks expire after about an hour. [Task fields](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Task.html) · [Container fields](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Container.html)

```
aws ecs describe-tasks \
  --profile PROFILE --region REGION --cluster CLUSTER --tasks TASK_ARN_1 TASK_ARN_2 \
  --query 'tasks[].{deployment:startedBy,definition:taskDefinitionArn,started:startedAt,stopping:stoppingAt,code:stopCode,reason:stoppedReason,health:healthStatus,containers:containers[].{name:name,health:healthStatus,exit:exitCode,reason:reason}}' \
  --output json --no-cli-pager
```

Then read the health check the failed revision defines, for every container, along with the service's grace period. Pass the full task definition ARN from the task, since a family name can resolve to a newer revision. [ContainerDefinition](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html) · [describe-task-definition](https://docs.aws.amazon.com/cli/latest/reference/ecs/describe-task-definition.html)

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

aws ecs describe-services \
  --profile PROFILE --region REGION --cluster CLUSTER --services SERVICE \
  --query 'services[0].{grace:healthCheckGracePeriodSeconds,deployments:deployments[].{id:id,definition:taskDefinition,failed:failedTasks}}' \
  --output json --no-cli-pager
```

Run the same `describe-task-definition` on the previous revision and compare the `healthCheck` blocks and images.

## What the settings mean

| Field | Default | Range | What it changes |
| --- | --- | --- | --- |
| `command` | none |  | `CMD` runs the arguments directly; `CMD-SHELL` runs them with the container's default shell. Exit code 0 is healthy, anything else a failure |
| `interval` | 30 s | 5 to 300 s | Time between checks |
| `timeout` | 5 s | 2 to 60 s | How long one check may take before it counts as a failure |
| `retries` | 3 | 1 to 10 | Failed checks before the container is `UNHEALTHY` |
| `startPeriod` | off | 0 to 300 s | Failures during this period do not count toward `retries`; a success during it marks the container healthy and later failures count |

The service's `healthCheckGracePeriodSeconds` applies on top. For that many seconds after a task first starts, the scheduler ignores unhealthy load balancer, VPC Lattice and container health checks; the default is 0. [HealthCheck](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_HealthCheck.html) · [CreateService](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_CreateService.html)

ECS monitors only the health check in the container definition. A `HEALTHCHECK` in the image's Dockerfile or a parent image is not monitored or reported unless the container definition specifies one, and the container definition's parameters override the image's. A team that moves its health check into the Dockerfile sees `UNKNOWN`, not a replacement. [Task healthStatus](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Task.html)

## What each result means

| Reading | Most likely cause | Next check |
| --- | --- | --- |
| The failing container is `UNHEALTHY`; its `healthCheck` or image changed in the revision | The release broke the check: a command, tool or shell missing from the new image, or a changed port or path | Run the command against the new image |
| `UNHEALTHY` only in the first minutes; healthy on tasks that survive longer | Start time exceeds `startPeriod` and the grace period | Compare the application's start time with both |
| `UNHEALTHY` on old and new tasks alike | Something the check calls, or the host, not the revision | Read what the command depends on |
| Every container `HEALTHY` or `UNKNOWN`, and the reason names ELB health checks | The load balancer's check | Read target health reason codes |
| A non-essential container `UNHEALTHY`, task `HEALTHY` | That container does not affect task health | Nothing stops the task for it; decide whether the sidecar should be essential |

To test the first row, run the health check command against the new image on a workstation, with the same entry point and shell the container definition uses, for example `docker run --rm --entrypoint sh IMAGE -c 'COMMAND'`. A `CMD-SHELL` check in an image that has no shell fails every time.

## An illustrative rollout, two outcomes

This fixture is fictional. The service `orders` moves from `orders:57` to `orders:58`. Both revisions define the same check:

```
{"command": ["CMD-SHELL", "curl -f http://localhost:8080/health || exit 1"], "interval": 30, "timeout": 5, "retries": 3}
```

In the first outcome, `orders:58` switches to a smaller base image. Its `app` container reports `UNHEALTHY` within two minutes of `startedAt` on every new task, while the target group shows those tasks healthy, because the load balancer's request reaches the application. Running the command against the new image prints that `curl` is not found. The application works, and the release removed the tool the health check needs. Changing the check to something the image contains, or adding the tool, is the fix.

In the second outcome, `orders:58` adds a cache warm-up that takes 100 seconds before the server listens. The check fails three times at 30-second intervals before the server is up, and the task is replaced before it could pass. Setting `startPeriod` above the start time lets the check begin counting once the server can answer; the service's grace period, if set, also delays the scheduler's reaction.

## Confirm on the replacement

After the change ships as a new revision, read `describe-tasks` on the new deployment's tasks a few intervals after start. Each essential container with a check should report `HEALTHY`, the task `healthStatus` should be `HEALTHY`, and the deployment's `failedTasks` should stay at zero.

## Where the reading stops

ECS records the status, not the command's output, so `healthStatus` says the check failed without saying how; running the command against the image or checking the application's logs gives the reason. If the ECS agent loses its connection to the ECS service, containers keep their last known status rather than turning `UNHEALTHY`. Container health checks need agent 1.17.0 or later on EC2 or platform version 1.1.0 or later on Fargate, and are not supported for services that use a Classic Load Balancer. [HealthCheck](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_HealthCheck.html)

A health check command that queries a database or another service turns a dependency outage into task replacements on every revision, which is a separate design question. For sorting the other stop codes, read the [stop code guide](/learn/ecs-task-stop-codes/).

## Questions

### Does ECS use the HEALTHCHECK in my Dockerfile?

No. The ECS agent monitors and reports only the health check in the container definition. A Dockerfile `HEALTHCHECK` without one in the task definition leaves the container's `healthStatus` as `UNKNOWN`.

### What is the difference between startPeriod and healthCheckGracePeriodSeconds?

`startPeriod` is part of a container's health check: failures during it do not count toward `retries`. `healthCheckGracePeriodSeconds` is a service setting: for that long after a task starts, the scheduler ignores unhealthy load balancer, VPC Lattice and container health checks.

### Why is my ECS task UNKNOWN instead of HEALTHY?

At least one essential container is `UNKNOWN` and none is `UNHEALTHY`. A container reports `UNKNOWN` while its check is being evaluated, when it has no health check defined, or when ECS has no status for it.

## 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](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [ECS EssentialContainerExited after a deploy: read the exit code](/learn/ecs-exit-codes-after-deploy/)
    
    Deployment failures The Proofline team November 22, 2026 7 min read
    
-   ### [Which ECS task stops came from your deployment? Read the stop code](/learn/ecs-task-stop-codes/)
    
    Deployment failures The Proofline team November 22, 2026 6 min read
