This Docker container runs Python scripts on a cron schedule using Alpine Linux.
482
Alpine-Cron is a lightweight, Docker-based cron job manager that allows you to schedule and run Python scripts with:
console, file, or both)scripts.config is updateddocker execPull the image from Docker Hub:
docker pull slipping/alpine-cron
Create a directory for logs and scripts:
mkdir logs scripts
Run the container:
docker run -d --name alpine-cron \
-v $(pwd)/logs:/logs \
-v $(pwd)/scripts:/scripts \
-e DEFAULT_TZ=UTC \
-e MAX_LOG_SIZE=10485760 \
-e LOG_LINES_TO_KEEP=5000 \
slipping/alpine-cron
scripts.config)All scripts are managed via a single YAML-based configuration file located at:
/scripts/scripts.config
Modify this file to define your cron jobs, logging preferences, and dependencies.
scripts.config):scripts:
hello:
script: hello.py
schedule: "* * * * *" # Required: Valid cron schedule
log_mode: "both" # Optional: Defaults to "file"
notify_mode: "on" # Optional: Defaults to "off"
requirements:
- requests # Optional: Dependencies
| Option | Required? | Description | Default |
|---|---|---|---|
script | ✅ Yes | Python script filename (must be in /scripts/) | N/A |
schedule | ✅ Yes | Cron job schedule (e.g., "0 * * * *") | N/A |
log_mode | ❌ No | console, file, or both | "file" |
notify_mode | ❌ No | on or off (Log when the script runs) | "off" |
requirements | ❌ No | List of Python dependencies (installed in venv) | None |
You can manually trigger any script inside the container:
docker exec alpine-cron run-script hello.py
This will:
Create a virtual environment if it doesn't exist
Install dependencies if needed
Run the script with logging
log_mode: console or both)docker logs alpine-cron --follow
log_mode: file or both)cat logs/hello.log
Whenever scripts.config is modified and saved, the container:
The following optional environment variables can be set when running the container:
| Variable | Description | Default |
|---|---|---|
LOG_DIR | Path to store script logs | "/logs" |
SCRIPTS_DIR | Path to store Python scripts | "/scripts" |
VENV_DIR | Path for virtual environments | "/venvs" |
CRON_DIR | Path for cron jobs | "/etc/crontabs" |
DEFAULT_TZ | Default timezone | "UTC" |
MAX_LOG_SIZE | Maximum log file size (bytes) | 10485760 (10MB) |
LOG_LINES_TO_KEEP | Lines to keep after rotation | 5000 |
To persist logs and scripts, modify your docker-compose.yml:
services:
alpine-cron:
image: slipping/alpine-cron
container_name: alpine-cron
restart: always
volumes:
- ./logs:/logs # Map log storage
- ./scripts:/scripts # Map scripts folder
environment:
- DEFAULT_TZ=UTC
- MAX_LOG_SIZE=10485760
- LOG_LINES_TO_KEEP=5000
Run it:
docker-compose up -d --build
docker logs alpine-cron)docker exec alpine-cron crontab -l
scripts.config is formatted correctly
docker exec alpine-cron cat /scripts/scripts.config
log_mode: both for the scriptdocker-compose restart
Content type
Image
Digest
sha256:bbead3504…
Size
35.8 MB
Last updated
over 1 year ago
docker pull slipping/alpine-cron