Essential container in task exited ☁️ AWS

ECS: Essential container in task exited (task keeps stopping)

The main (essential) container stopped, so ECS stopped the whole task and the service keeps replacing it.

Seen on: AWS

Meaning

The message is generic: look at the container’s exit code and its CloudWatch logs. Exit 137 means OOM or killed by health checks; exit 1 is an app error (config, env vars, DB connection).

Common causes

  • Application crash on startup (missing env/secret, bad config)
  • Out of memory (exit 137)
  • Failing health check → task replaced
  • Wrong command/entrypoint for the image

⚡ Quick fix

  1. Read container exit code and reason in the stopped task
  2. Check the awslogs CloudWatch log stream
  3. Raise memory or fix health check grace period

Detailed fix by platform

AWS CLI

  1. bash
    aws ecs describe-tasks --cluster app --tasks $TASK --query 'tasks[0].containers[].[name,exitCode,reason]'
    aws logs tail /ecs/web --since 15m

How to diagnose

  1. Exit code — 1, 137, 139?
  2. Logs — Last lines before exit
  3. Health — Target group / container health checks

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.