---
title: "ECS container won't start: CannotStartContainerError or exit code 127 | Proofline"
description: "Read the stop code and startedAt first: a container that never started has no start time, while a process that exited at once has one and an exit code."
url: https://proofline.sh/learn/ecs-cannotstartcontainer-command-not-found/
---

[Learning center](/learn/)

# ECS container won't start: CannotStartContainerError or exit code 127

Read the stop code and startedAt first: a container that never started has no start time, while a process that exited at once has one and an exit code. Then compare the revision's entryPoint and command with the image's own entry point and command, since both failures usually come from a program that is not where the revision says.

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

## Two records for one mistake

A release changes the image or the task definition, and every new task stops within seconds. The same root cause, a program that is missing from the image or not on its `PATH`, leaves one of two records depending on how the revision starts it:

-   **The runtime cannot start the container.** With exec form, such as `"entryPoint": ["/app/server"]`, the runtime itself executes `/app/server`. If the file is not there, no process starts. The stopped reason begins with `CannotStartContainerError`, and the task has no `startedAt`. AWS lists this category among the stopped-task errors for tasks that failed to start. [CannotStartContainerError](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cannot-start-container.html) · [Stopped task error codes](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/stopped-task-error-codes.html)
-   **The process starts and exits at once.** With a shell, such as `"entryPoint": ["sh", "-c"]` and `"command": ["server --port 8080"]`, the shell is the process that starts, and it is present. It then fails to find `server` and exits with status 127, the status shells return for a command they cannot find. The task has a `startedAt`, stops with `EssentialContainerExited`, and the container reports `exitCode` 127. [Bash command search](https://www.gnu.org/software/bash/manual/html_node/Command-Search-and-Execution.html) · [Task fields](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Task.html)

A nearby exit code reads differently. Status 126 means the file was found but could not be run. Docker uses the same 126 and 127 meanings for a contained command that cannot be invoked or cannot be found. [POSIX command exit status](https://pubs.opengroup.org/onlinepubs/9799919799/utilities/command.html) · [Docker exit status](https://docs.docker.com/engine/containers/run/)

Two neighbors leave records that look like these. An image built for another CPU architecture also exits at once, usually with an exec format error; see [platform mismatch](/learn/ecs-image-platform-mismatch/). A container held back by a `dependsOn` condition never starts either, with a different reason; see [container dependencies](/learn/ecs-container-dependency-blocks-start/).

## Read the stop code and the start time

Use a read-only profile and replace the uppercase placeholders.

```
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,overrides:overrides.containerOverrides[].{name:name,command:command},containers:containers[].{name:name,image:image,digest:imageDigest,exit:exitCode,reason:reason}}' \
  --output json --no-cli-pager
```

| `stopCode` | `startedAt` | Container | Reading | Next read |
| --- | --- | --- | --- | --- |
| `TaskFailedToStart` | Empty | `reason` begins `CannotStartContainerError` and says the executable was not found | The runtime could not execute the configured program | The exec-form path against the image |
| `EssentialContainerExited` | Set | `exitCode` 127 | A shell or wrapper started and could not find the program | The log stream, then the shell command against the image |
| `EssentialContainerExited` | Set | `exitCode` 126 | The program exists and could not be run | File permissions or the image platform |
| `EssentialContainerExited` | Set | Another nonzero code | The program ran and exited on its own | The application's logs |

`overrides` matters for a task started by `run-task` or a scheduled rule, because a container override replaces the command in the task definition. [ContainerOverride](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerOverride.html)

For the exit-code case, the log stream usually holds the shell's own message, because the shell ran long enough to print it. For the `CannotStartContainerError` case there is no application output at all.

## Compare the revision with the image

ECS passes the revision's `entryPoint` as the container's entry point and `command` as its command, the same as `docker run --entrypoint` and the trailing command. A field the revision leaves empty keeps the image's value. [ContainerDefinition](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html)

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

Then read the image's own settings. These commands sign Docker in to ECR and download the image to your machine; pull by the digest the task reported so you inspect the image that failed. [Registry authentication](https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry_auth.html) · [docker image inspect](https://docs.docker.com/reference/cli/docker/image/inspect/)

```
docker pull IMAGE_ACCOUNT.dkr.ecr.IMAGE_REGION.amazonaws.com/REPOSITORY@sha256:DIGEST
docker image inspect \
  --format 'entrypoint={{json .Config.Entrypoint}} cmd={{json .Config.Cmd}} workdir={{json .Config.WorkingDir}} path={{json .Config.Env}}' \
  IMAGE_ACCOUNT.dkr.ecr.IMAGE_REGION.amazonaws.com/REPOSITORY@sha256:DIGEST
```

`.Config.Env` includes the image's `PATH`. With an exec-form entry point, the program the container runs is the entry point followed by the command as its arguments. To check that the file exists in the image, list it without running the image's own entry point. [Choosing between CMD and ENTRYPOINT](https://www.docker.com/blog/docker-best-practices-choosing-between-run-cmd-and-entrypoint/)

```
docker run --rm --entrypoint ls \
  IMAGE_ACCOUNT.dkr.ecr.IMAGE_REGION.amazonaws.com/REPOSITORY@sha256:DIGEST -l /app/server
```

This needs `ls` in the image. A minimal image without a shell or `ls`, such as one built from scratch, cannot be listed this way; read the build's final stage instead.

## What each comparison means

| Finding | Reading | Change |
| --- | --- | --- |
| The revision's path does not exist in the image | The image moved or renamed the program, often in a multi-stage build that no longer copies it | Correct the path in the revision, or copy the program into the final image |
| The program exists but is not on the image's `PATH`, and the revision names it without a directory | A bare name needs `PATH` to find it | Use an absolute path |
| The revision sets `entryPoint` or `command` and the image changed its own | The revision overrides a value the new image no longer supports | Remove the override and let the image decide, or update it |
| A relative path, and `workingDirectory` differs from the image's | The path resolves from another directory | Set `workingDirectory` or use an absolute path |
| The file exists and runs locally | Not a missing command | Check the exit code against the application's logs and the image platform |

## An illustrative release, two outcomes

These records are fictional. `orders:58` changed the base image of `orders` to a slimmer one. The new image installs the server at `/usr/local/bin/orders-server` instead of `/app/server`.

-   **Outcome A.** Revision 58 still sets `"entryPoint": ["/app/server"]`. Tasks stop with `TaskFailedToStart`, no `startedAt`, and a `CannotStartContainerError` that says the executable was not found. `docker image inspect` shows the image's entry point is `["/usr/local/bin/orders-server"]`. Remove `entryPoint` from the revision.
-   **Outcome B.** Revision 58 sets `"entryPoint": ["sh", "-c"]` and `"command": ["server --port 8080"]`. Tasks start, stop with `EssentialContainerExited`, and report exit code 127; the log stream shows the shell saying `server` was not found. The new image has no program named `server` anywhere on its `PATH`. Change the command to `/usr/local/bin/orders-server --port 8080`.

Both outcomes come from the same image change. Outcome B is easy to mistake for a crashing application because the task did start; the exit code is what separates them.

## Confirm on the replacement

A replacement task should reach `RUNNING` with a `startedAt` and stay up past the seconds in which the old ones stopped. If the container has a restart policy, ECS can restart an exiting container without replacing the task, so also check that the container is not restarting in place. [Container restart policy](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerRestartPolicy.html)

## Where this check misleads

Exit code 127 is a convention: a wrapper script can exit with 127 for its own reasons, and the POSIX `command` and `nohup` utilities also use it for their own errors. Read the log line before you act on the number. The `CannotStartContainerError` category also covers other start failures, such as the container exceeding its memory limit at start, so read the rest of the reason. The stopped reason is free text that AWS rewords; the [signature table](/learn/aws-deployment-failure-signatures/) sorts on stop codes for that reason.

## Questions

### What does exit code 127 mean for an ECS container?

The container's process started and reported that it could not find a command, which is how shells report a missing program. Compare the command the revision runs with the files and `PATH` in the image.

### Why does a task with CannotStartContainerError have no logs?

The runtime could not start the container's process, so nothing ran to write output. The stopped reason and the image's configuration are the evidence.

### Should I set entryPoint in the task definition?

Only when you mean to override the image. A revision that sets `entryPoint` keeps it when the image changes, so an image that moves its program breaks the revision without any task definition change.

## 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

-   ### [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
    
-   ### [ECS image built for the wrong CPU architecture or OS](/learn/ecs-image-platform-mismatch/)
    
    Deployment failures The Proofline team November 22, 2026 6 min read
