Skip to content

Another approach that might be more portable #4

@sohailsomani

Description

@sohailsomani

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 docker@ekito.fr
 
-# 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions