garrcomm/crontainer

By garrcomm

Updated over 1 year ago

Container that helps run cronjobs

Image
Message queues
1

350

garrcomm/crontainer repository overview

Crontainer

This container can execute scheduled tasks.

Scheduled tasks can be;

  • Webhook calls to all kinds of web services.
    For this, curl --silent --request [method] --location [url] is used.
  • Executables in an active container; if the volume /run/docker.sock is mounted correctly, it's also possible to execute jobs in other containers.
    To do this, docker container exec --tty [container] [command] is used.
  • Executables in an image; if the volume /run/docker.sock is mounted correctly, it's also possible to execute jobs in other containers.
    To do this, docker container run --rm --tty [image] [command] is used.
  • Remote ssh executions with a private key exchange.
    To do this, ssh -T -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -o UserKnownHostsFile=~/known_hosts -i ~/id_rsa "user@hostname" [command] could be executed.
Installation instructions

There are two easy ways to start Crontainer. By command line and with a Docker Compose file.

In both examples you'll see a few variables that can be changed to your needs:

  • The volume mount from /home/user/crontainer_data to /etc/crontainer can be replaced to a folder on the host system where Crontainer can store its persistent data.
  • The volume mount /run/docker.sock to /run/docker.sock is used to execute jobs in other Docker containers. Depending on your host configuration, it's also possible this can be replaced to /run/user/$(id -u)/docker/docker.sock:/run/docker.sock or something completely different.
    As long as it points to the docker.sock on the host system, it'll be fine.

At the first run, you'll be asked for a new username and password.

Start Crontainer by command line

docker container run --detach --restart always -p '80:80' --name crontainer \
    --volume '/run/docker.sock:/run/docker.sock' \
    --volume '/home/user/crontainer_data:/etc/crontainer' \
    garrcomm/crontainer:latest

Start Crontainer with a compose file

services:
  crontainer:
    image: garrcomm/crontainer:latest
    volumes:
      # By making a volume of the Docker socket, we can access other containers to run jobs inside those.
      - /run/docker.sock:/run/docker.sock
      # This volume defines where to store the crontab.db and htpasswd file.
      - /home/user/crontainer_data:/etc/crontainer
    ports:
      - "80:80"
    restart: always

UNIX cron format

The cron format contains 5 parts:

PositionUnitAllowed values
1minute0-59
2hour0-23
3day of the month1-31
4month1-12 where 1 is January, 2 February, etcetera.
Can also contain the three letter abbreviation jan, feb, etcetera in lower or uppercase.
5day of the week0-7 where 0 and 7 are Sunday, and 1 to 6 are Monday to Saturday.
Can also contain the three letter abbreviation mon, tue, wed, etc.
Always matches

When using an asterisk (*) will cause it to match every value.

Lists

Multiple values can be comma separated. So 1,2,3 will match the values 1 to 3, but nothing else.
The same works for months and days, jan,feb matches the first two months and mon,wed matches each Monday and Wednesday.

Ranges

It's also possible to provide a range by separating two values with a dash (-). So 1-6 matches all values from 1 to 6.
The same works for months and days, so jun-sep will match all months from June to September and mon-fri matches all working days.

Step values

Step values are two values separated by a slash (/).

Depending on the value before the slash, the following happens if we apply it to the minute value:

  • */5 Matches every five minutes, so 0, 5, 10, 15, 20, etc.
  • 3/2 Matches every two minutes from the 3rd minute on, so 3, 5, 7, 9, 11 etc.
  • 8-20/2 Matches every two minutes in range 8 to 20, so 8, 10, 12, 14, 16, 18, 20.

Tag summary

Content type

Image

Digest

sha256:eccf18e38

Size

31.5 MB

Last updated

over 1 year ago

docker pull garrcomm/crontainer