[英]AWS CloudWatch log stream is empty while Docker container logs are full
I'm creating cron docker image, based on ubuntu image.我正在创建基于 ubuntu 图像的 cron docker 图像。 I would use this tutorial, but cron won't have PID 1, not 2 and not even 10. I found a solution to run cron in foreground, check it using healthcheck and view logs of command using tail -f
Locally all is perfect, but when I deploy it to ECS Fargate logs are empty我会使用本教程,但 cron 不会有 PID 1,没有 2,甚至没有 10。我找到了一个在前台运行 cron 的解决方案,使用 healthcheck 检查它并使用tail -f
查看命令日志在本地一切都很完美,但是当我将它部署到 ECS Fargate 时,日志是空的
Main issue主要问题
docker logs -f cron
displays output, but logs in cloudwatch are empty docker logs -f cron
显示输出,但是cloudwatch中的日志是空的
Additional information附加信息
I created Dockerfile with following ENTRYPOINT and CMD我使用以下 ENTRYPOINT 和 CMD 创建了 Dockerfile
COPY crontab /etc/crontab
COPY script.sh /root/script.sh
ENTRYPOINT ["tini", "--", "/usr/bin/docker-entrypoint.sh"]
CMD prepare.sh tail -f /var/log/script.log
prepare.sh
content: prepare.sh
内容:
# some preparation commands...
cron -L 15
exec "$@"
docker-entrypoint.sh
also has at the end exec "$@"
. docker-entrypoint.sh
还有exec "$@"
。
crontab
content: crontab
内容:
*/3 * * * * root /root/script.sh >> /var/log/script.log
So, the last command is tail -f /var/log/script.log
所以,最后一个命令是tail -f /var/log/script.log
In order for your container's logs to appear in CloudWatch logs, you need to setup your Task Definition to use the awslogs
log driver.为了让您的容器日志显示在 CloudWatch 日志中,您需要设置您的任务定义以使用awslogs
日志驱动程序。
Documentation on how to do this can be found here . 可以在此处找到有关如何执行此操作的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.