How do I troubleshoot Amazon ECS tasks stopping or failing to start while my container exits?
"My Amazon Elastic Container Service (Amazon ECS) container exits unexpectedly, and tasks stop or fail to start. How can resolve the issue?"
"My Amazon Elastic Container Service (Amazon ECS) container exits unexpectedly, and tasks stop or fail to start. How can resolve the issue?Short descriptionYour containers can exit due to application issues, resource constraints, or other issues.For task failure due to image issues, see How do I resolve the "Image does not exist" error when my tasks fail to start in my Amazon ECS cluster?For AWS Fargate tasks that fail due to network configuration or resource constraint issues, see Stopped tasks error codes.ResolutionTo identify why your tasks stopped, follow these troubleshooting steps:Check for diagnostic information in the service event log.Check stopped tasks for errors. Note: You can see stopped tasks in the returned results for at least one hour.If you already have a log driver configured, then check your application logs for application issues. Otherwise, use the log configuration options in your task definition to send logs to a custom log driver for the container. For example, you can send the logs to Amazon CloudWatch or use a supported log driver. Note the following information on logs, depending on your task's launch type:For ECS tasks other than Fargate: If you're using the default json-file logging driver with the Amazon Elastic Compute Cloud (Amazon EC2) launch type, run the docker logs yourContainerID command. This command checks the Docker logs of the container on your ECS container instance.For Fargate tasks: Captured logs show the command output that you see in an interactive terminal if you run the container locally, in the STDOUT and STDERR I/O streams. The awslogs log driver passes these logs from Docker to Amazon CloudWatch Logs.To address memory constraint issues, follow the instructions at How can I allocate memory to tasks in Amazon ECS?If the awslogs log driver is configured in your task definition, then check Viewing awslogs container logs in CloudWatch Logs.Follow"