├── Dockerfile ├── README.md └── crontab /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:latest 2 | MAINTAINER docker@ekito.fr 3 | 4 | # Add crontab file in the cron directory 5 | ADD crontab /etc/cron.d/hello-cron 6 | 7 | # Give execution rights on the cron job 8 | RUN chmod 0644 /etc/cron.d/hello-cron 9 | 10 | # Create the log file to be able to run tail 11 | RUN touch /var/log/cron.log 12 | 13 | #Install Cron 14 | RUN apt-get update 15 | RUN apt-get -y install cron 16 | 17 | 18 | # Run the command on container startup 19 | CMD cron && tail -f /var/log/cron.log 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-cron 2 | An example of running cron job in a docker container 3 | -------------------------------------------------------------------------------- /crontab: -------------------------------------------------------------------------------- 1 | * * * * * root echo "Hello world" >> /var/log/cron.log 2>&1 2 | # Don't remove the empty line at the end of this file. It is required to run the cron job 3 | --------------------------------------------------------------------------------