Run any Python script on a custom cron schedule with environment-based control and logging.
Docker Image: gurkiratm/python-cron
Pull command:
docker pull gurkiratm/python-cron:latest
This image runs any user-supplied Python script on a recurring schedule using cron, with parameters passed via environment variables. It installs dependencies at runtime and logs output to a configurable or timestamped file inside the container.
- β
Run any script via
PYTHON_SCRIPT_PATH - β
Schedule via
CRON_SCHEDULE(default:0 9 * * *) - β
Logs to dynamic or custom
LOG_FILE - β
Virtualenv auto-created at
/app/.venv - β
Installs
requirements.txtviaREQUIREMENTS_FILE(default:/app/requirements.txt) - β Lightweight Alpine base image
- β
Uses
busybox crondrunning in foreground for clean logs
| Variable | Required | Description |
|---|---|---|
PYTHON_SCRIPT_PATH |
β Yes | Full path to the Python script inside the container |
CRON_SCHEDULE |
β No | Cron format schedule (default: 0 9 * * *) |
LOG_FILE_PATH |
β No | Log file name (Default: /app/script_python_dYYYYMMDD_tHHMMSS.log) |
REQUIREMENTS_FILE |
β No | Path to requirements.txt (Default: /app/requirements.txt : empty) |
Mount your Python script and any inputs:
-v $(pwd)/scripts:/data:Zdocker run --rm \
-v $(pwd)/scripts:/data:Z \
-e PYTHON_SCRIPT_PATH="/data/myscript.py" \
-e CRON_SCHEDULE="*/10 * * * *" \
-e REQUIREMENTS_FILE="/data/requirements.txt" \
-e LOG_FILE_PATH="myscript.logs" \
gurkiratm/python-cron
Script output will be logged to:
${LOG_FILE_PATH} if provided
Or the default: /app/script_python_dYYYYMMDD_tHHMMSS.log
To view logs:
docker exec <container-name> cat <LOG-FILE-PATH>
docker logs <container-name>
docker build -t python-cron-runner .
Gurkirat Singh