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 "
The process with PID 0 is the cron daemon in my container. Entrypoint starts cron in foreground:
/usr/sbin/crond -f
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"
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" ?
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
using the default cron utility (busybox)
FROM alpine:3.7
# Setting up crontab
COPY crontab /tmp/crontab
RUN cat /tmp/crontab > /etc/crontabs/root
CMD ["crond", "-f", "-l", "2"]
* * * * * echo "Crontab is working - watchdog 1"
/proc/1/fd/1
inside the crontab declaration lineFROM centos:7
RUN yum -y install crontabs
ADD crontab /etc/cron.d/crontab
RUN chmod 0644 /etc/cron.d/crontab
RUN crontab /etc/cron.d/crontab
CMD ["crond", "-n"]
* * * * * echo "Crontab is working - watchdog 1" > /proc/1/fd/1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With