thesuhu/docker-cron
Run your cron job inside a docker container
15
Docker images used to run cron job in a Docker container.
First, create config file. For example create file cronjobs
:
# example alpine config crond
# do daily/weekly/monthly maintenance
# min hour day month weekday command
# */15 * * * * run-parts /etc/periodic/15min
# 0 * * * * run-parts /etc/periodic/hourly
# 0 2 * * * run-parts /etc/periodic/daily
# 0 3 * * 6 run-parts /etc/periodic/weekly
# 0 5 1 * * run-parts /etc/periodic/monthly
* * * * * date
* * * * * echo "${CUSTOM_ENV_VAR}"
Then change ownership to root sudo chown root:root cronjobs
and run container and mount config file to /etc/crontabs/root
inside container:
docker run -d --name cron -e CUSTOM_ENV_VAR=foobar -v `pwd`/cronjobs:/etc/crontabs/root thesuhu/docker-cron
Restart container after modify the config file on host.
docker pull thesuhu/docker-cron