通过docker日志查看cron输出,无需使用额外的文件 [英] See cron output via docker logs, without using an extra file

查看:479
本文介绍了通过docker日志查看cron输出,无需使用额外的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在docker容器中运行 cron。

每天执行一个脚本。

我想通过 docker logs查看此脚本的输出

I am running "cron" in a docker container.
Every day a script is executed.
The output of this script I would like to see via "docker logs "

PID为0的进程是cron守护程序我的容器。入口点在前台启动cron:

The process with PID 0 is the cron daemon in my container. Entrypoint starts cron in foreground:

/usr/sbin/crond -f 

我了解,我可以将脚本输出重定向到文件 path / to / logs

I understand, that I could redirect the script output to a file "path/to/logs"

07 2 * * * /data/docker/backup_webserver/backupscript.sh >> path/to/logs

并按如下所示启动容器以查看日志

and start the container as following to see the logs

"tail -f path/to/logs" 

但是,在容器运行期间,文件 path / to / logs将增长。

是否可以从crontab直接登录到 docker日志?

But then the file "path/to/logs" would grow during the runtime of the container.
Is there a possibility to log from crontab, directly to "docker logs" ?

推荐答案

将您的cron文件更改为以下

Change your cron file to below

07 2 * * * /data/docker/backup_webserver/backupscript.sh > /dev/stdout

这将确保日志进入容器输出

This will make sure the logs go to the container output

这篇关于通过docker日志查看cron输出,无需使用额外的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆