- Shell 81.6%
- Dockerfile 18.4%
|
|
||
|---|---|---|
| .gitignore | ||
| crontab | ||
| Dockerfile | ||
| entrypoint.sh | ||
| LICENSE | ||
| README.md | ||
| script.sh | ||
docker-crontab
Alpine-based image to run scripts in crontab. It's meant to be used by binding a file containing your crontab config, as well as any scripts you may need to run.
This image is a base alpine image that adds curl and tini (as an init system for the entrypoint.sh). Additional packages can be installed at runtime, see INSTALL_PACKAGES below. Any environment variables on the container are make available to any scripts running in crontab.
Simply create a local file containing your job(s) and bind it to /crontab. See the usage example below.
By default the image will run as user 1000:1000 with the username cronuser. This can be customized by passing environment values.
Any scripts you want to run can be bind mounted to /workspace. The permissions on that path are adjusted in the entrypoint to set $CRON_USER:$CRON_GID as the owner. Note, however, that any files placed there will not have their permissions adjusted, so make sure they are correct on the host and $CRON_USER:$CRON_GID will have access to run them.
| Env | Description | Default |
|---|---|---|
| CRON_USER | User for the cron user | cronuser |
| CRON_UID | UID for the cron user | 1000 |
| CRON_GID | GID for the cron user | 1000 |
| RUN_AS_ROOT | Run crons as root instead of creating a user | (empty) |
| INSTALL_PACKAGES | Space-separated list of additional packages to install at startup | (none) |
Usage
To run the image with the default setup:
docker run -it --rm \
-v /path/to/crontab:/crontab \
-v /path/to/script.sh:/workspace/scripts.sh \
git.w33ble.com/w33ble/docker-crontab
Here is an example that will override the cron user details and run the container with the same timezone as the host:
docker run -it --rm \
-e CRON_USER=myuser \
-e CRON_UID=1001 \
-e CRON_GID=1001 \
-v /etc/localtime:/etc/localtime:ro \
-v /path/to/crontab:/crontab \
git.w33ble.com/w33ble/docker-crontab
To run crons as root (useful for managing permissions on mounted volumes):
docker run -it --rm \
-e RUN_AS_ROOT=1 \
To install additional alpine packages at startup:
docker run -it --rm \
-e INSTALL_PACKAGES="rsync jq" \
-v /path/to/crontab:/crontab \
git.w33ble.com/w33ble/docker-crontab
Credits
The entrypoint.sh script that powers this image was adapted from theohbrothers/docker-alpine-cron.