Skip to content

Instantly share code, notes, and snippets.

@vnext-nguyen-quyen
Last active January 9, 2023 07:40
Show Gist options
  • Save vnext-nguyen-quyen/eb97f19381dec585522c253dc23399b0 to your computer and use it in GitHub Desktop.
Save vnext-nguyen-quyen/eb97f19381dec585522c253dc23399b0 to your computer and use it in GitHub Desktop.
See cron log ouput with docker logs
1. Alpine (No need for redirection)
using the default cron utility (busybox)
## Dockerfile
=====
FROM alpine:3.7
# Setting up crontab
COPY crontab /tmp/crontab
RUN cat /tmp/crontab > /etc/crontabs/root
CMD ["crond", "-f", "-l", "2"]
=====
## Crontab
=====
* * * * * echo "Crontab is working - watchdog 1"
=====
2. Centos
Redirection to /proc/1/fd/1 inside the crontab declaration line
## Dockerfile
=====
FROM 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"]
=====
## Crontab
=====
* * * * * echo "Crontab is working - watchdog 1" > /proc/1/fd/1
=====
=> Test show cron ouput with docker logs {container_name}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment