thesuhu/docker-cron

By thesuhu

Updated almost 2 years ago

Run your cron job inside a docker container

Image
Message Queues

15

docker-cron

GitHub workflowDocker pull

Docker images used to run cron job in a Docker container.

Usage

First, create config file. For example create file cronjobs:

alpine
# 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 Command

docker pull thesuhu/docker-cron