Example implementation of cron jobs on Docker/Aptible
git clone https://github.com/aptible/docker-cron-example
cd docker-cron-example/
make run
The example will print "aptible/docker-cron-example" once every minute.
To include within an Aptible app, copy the following 5 body lines of the Dockerfile to your own Dockerfile:
RUN apt-get -y install rsyslog
ADD files/crontab /app/crontab
RUN crontab /app/crontab
ADD files/bin/start-cron.sh /usr/bin/start-cron.sh
RUN chmod +x /usr/bin/start-cron.sh
RUN touch /var/log/cron.log
- Installs
rsyslog
http://www.rsyslog.com/ - Copies
crontab
file from repo/app data to Docker and installs to user'scrontab
- Copies
start-cron.sh
from repo/app data to Docker - Adjusts permissions
- Creates log file at
/var/log/cron.log
Then, copy files
to your own repo, editing files/etc/crontab
with your own task, and * * * * *
with your own desired job schedule.
Crash course on cron(tab) job schedules https://en.wikipedia.org/wiki/Cron#Format. Consider the asterisk (*
) like a wild card. Left to rigt the argument positions are:
[Minute Arg] [Hours Arg] [Day of month arg] [Month arg] [Day of week]
To run every 5 minutes:
*/5 * * * *
To run every 5 hours:
0 */5 * * *
Finally, add an entry in your Procfile for the new cron
process:
cron: /usr/bin/start-cron.sh
MIT License, see LICENSE for details.
Copyright (c) 2015 Aptible and contributors.