This container runs a regularly scheduled cron job, specified through environment variables.
This container uses two environment variables:
cron_freq
: The cron timing string e.g. '*/1 * * * *'
(help)
cron_cmd
: The command for cron to run e.g. 'echo hello > world.txt'
Two examples of usage will be given, the envisioned usage of the pre-built package (available here) and details on how to build and run the package locally.
Two methods for using the pre-built package are detailed here, using docker run and docker-compose.
To use the pre-built package from the command line the docker run command is used with the user specifying environment varables. For example, to echo the date command into a file every minute:
$ docker run --env cron_freq='*/1 * * * *' --env cron_cmd='date >> /crontest.csv' ghcr.io/uomresearchit/container-cron
To use the pre-built package in a docker-compose swarm (see also this file):
services:
container-cron:
image: ghcr.io/uomresearchit/container-cron
environment:
- cron_freq=*/1 * * * *
- cron_cmd=date >> /crontest.csv
The following examples give usage for locally developing and testing the package.
To build locally:
docker build . -t container-cron
To run a locally built package:
docker run --env cron_freq='*/1 * * * *' --env cron_cmd='date >> /crontest.csv' container-cron
##̣## Compose usage ####
To use a local image in docker-compose
services:
container-cron:
build: .
environment:
- cron_freq=*/1 * * * *
- cron_cmd=date >> /crontest.csv