docker-cron
docker-cron copied to clipboard
Another approach that might be more portable
Thanks for posting this, it got me started. I found an approach (using crontab - < /path/to/crontab
) that worked better for me. Thought I would post it here in case others found it useful.
modified Dockerfile
@@ -1,19 +1,16 @@
FROM ubuntu:latest
MAINTAINER [email protected]
-# Add crontab file in the cron directory
-ADD crontab /etc/cron.d/hello-cron
-
-# Give execution rights on the cron job
-RUN chmod 0644 /etc/cron.d/hello-cron
-
# Create the log file to be able to run tail
RUN touch /var/log/cron.log
#Install Cron
RUN apt-get update
RUN apt-get -y install cron
+# Install the crontab
+ADD crontab /tmp/crontab
+RUN crontab /tmp/crontab && rm /tmp/crontab
# Run the command on container startup
CMD cron && tail -f /var/log/cron.log
modified crontab
@@ -1,2 +1,2 @@
-* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
+* * * * * echo "Hello world" >> /var/log/cron.log 2>&1
# Don't remove the empty line at the end of this file. It is required to run the cron job
Can you please explain why this is better?
Can you please explain why this is better?
Because it doesn't require a chmod. Also, no need for "root" in the cron line.