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
- Read container exit code and reason in the stopped task
- Check the awslogs CloudWatch log stream
- Raise memory or fix health check grace period
Detailed fix by platform
AWS CLI
- 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
- Exit code — 1, 137, 139?
- Logs — Last lines before exit
- 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:
Similar errors
- ACR unauthorized Azure Container Registry: unauthorized: authentication required, visit https://aka.ms/acr/authorization (AKS ErrImagePull 401)
- CannotPullContainerError ECS task stopped: CannotPullContainerError: pull image manifest has been retried ... / ref pull has been retried
- Container failed to start Cloud Run: The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable
Most viewed in AWS
Other ways to find it
🧠 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026