How can I get logs of my task failed container

0

I am using docker compose to run my ecs fargate service, and got error AggregatorService TaskFailedToStart: Task failed to start.

How can I get logs of my service and know why task failed?

已提问 2 年前9471 查看次数
2 回答
0
已接受的回答

So you might want to check whether the log group was created and deleted as the service tasks failed to start. If the log group is created as part of the deployment in CFN, it might just have been deleted as it rolled back.

Best way to figure out what's happened is to go to ECS -> cluster -> services -> Tasks. There, once you see your task pending, click on it. Expand the container, and you will be able to find a shortcut link to the container's log stream. Equally you will be able to see the exit code. If your app in docker failed before doing any logging, which is possible, then you can figure that out with the exit code (most likely, exit !=0).

You could "patch" your dockerfile or entrypoint to print out "Hello, I am starting" right before your main app starts. That will tell you whether the task failed because of your app or due to something else, i.e, lack of permissions / wrong image .. etc.

If you want to generate the CFN templates for your services to be deployed so that you can have a look into it and possibly tweak things, try out ECS Compose-X. Achieves the same thing as the docker ecs plugin, but does it in a very different way and has lots of different features. Either way, hope the guidelines above help.

profile picture
已回答 2 年前
  • Yes, I should not test in the docker compose file. I should test in the ecs cluster manually first.

0

Hello,

You should be able to get logs for ECS in CloudWatch if you have logging setup in Container Definition. Please refer to https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_awslogs.html for using awslogs driver to log into CloudWatch.

For error codes related to ECS, please see https://docs.aws.amazon.com/AmazonECS/latest/userguide/stopped-task-error-codes.html for more information.

Thank you.

Regards,
Franky

AWS
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则