Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another approach that might be more portable #4

Open
sohailsomani opened this issue May 28, 2019 · 2 comments
Open

Another approach that might be more portable #4

sohailsomani opened this issue May 28, 2019 · 2 comments

Comments

@sohailsomani
Copy link

sohailsomani commented May 28, 2019

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
@ivanperez-keera
Copy link

Can you please explain why this is better?

@necmettin
Copy link

Can you please explain why this is better?

Because it doesn't require a chmod.
Also, no need for "root" in the cron line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants