How do I troubleshoot Amazon ECS tasks that stop or fail to start while my container exits?

2 minute read
0

My Amazon Elastic Container Service (Amazon ECS) container exits unexpectedly, and tasks stop or fail to start.

Short description

Your containers can exit because of image issues, application issues, resource constraints, or other issues.

For task failure because of 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 unexpectedly stop, see Amazon ECS stopped tasks error codes for the Fargate launch type for all possible error messages.

Resolution

To identify why your tasks stopped, complete the following tasks:

  • Check for diagnostic information in the service event log.
  • Check stopped tasks for errors.
    Note: You can use the list-tasks command to 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. For example, if the awslogs log driver is configured in your task definition, then view the awslogs container logs in Amazon CloudWatch. Or, use the log configuration options in your task definition to send logs to a supported log driver for the container. Note the following information on logs, depending on your task's launch type:
    For ECS tasks other than Fargate: If you use the default json-file logging driver with the Amazon Elastic Compute Cloud (Amazon EC2) launch type, then run the docker logs <yourContainerID> command. This command checks the Docker logs of the container on your ECS container instance. For more information on the JSON-file logging driver, see JSON File logging driver on the Docker website.
    For Fargate tasks: By default, the logs that are captured show the command output that you might see in an interactive terminal if you ran the container locally. These command outputs are 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?
AWS OFFICIAL
AWS OFFICIALUpdated 12 days ago