HUB
Sign inSign up

slipping/alpine-cron

By slipping

•Updated over 1 year ago

This Docker container runs Python scripts on a cron schedule using Alpine Linux.

Image
0

482

slipping/alpine-cron repository overview

⁠Alpine-Cron: Lightweight Docker-Based Cron Job Manager

Alpine-Cron is a lightweight, Docker-based cron job manager that allows you to schedule and run Python scripts with:

  • Automatic environment setup (venv & dependencies)
  • Flexible logging (console, file, or both)
  • Automatic cron job reloading when scripts.config is updated
  • Manual execution of scripts via docker exec

⁠Getting Started

⁠Installation

Pull 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

⁠Configuration (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.

⁠Example Configuration (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
OptionRequired?DescriptionDefault
script✅ YesPython script filename (must be in /scripts/)N/A
schedule✅ YesCron job schedule (e.g., "0 * * * *")N/A
log_mode❌ Noconsole, file, or both"file"
notify_mode❌ Noon or off (Log when the script runs)"off"
requirements❌ NoList of Python dependencies (installed in venv)None

⁠Running Scripts Manually

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


⁠Viewing Logs

⁠View Docker Logs (for log_mode: console or both)
docker logs alpine-cron --follow
⁠View Individual Script Logs (for log_mode: file or both)
cat logs/hello.log

⁠Auto-Reloading Cron Jobs

Whenever scripts.config is modified and saved, the container:

  1. Detects the change
  2. Validates the new configuration
  3. Automatically reloads cron jobs without restarting the container 🎉

⁠Environment Variables

The following optional environment variables can be set when running the container:

VariableDescriptionDefault
LOG_DIRPath to store script logs"/logs"
SCRIPTS_DIRPath to store Python scripts"/scripts"
VENV_DIRPath for virtual environments"/venvs"
CRON_DIRPath for cron jobs"/etc/crontabs"
DEFAULT_TZDefault timezone"UTC"
MAX_LOG_SIZEMaximum log file size (bytes)10485760 (10MB)
LOG_LINES_TO_KEEPLines to keep after rotation5000

⁠🛠 Docker Compose Example

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

⁠Common Issues & Fixes

⁠Scripts Not Running
  • Check the logs (docker logs alpine-cron)
  • Verify cron jobs exist inside the container:
    docker exec alpine-cron crontab -l
    
  • Ensure scripts.config is formatted correctly
    docker exec alpine-cron cat /scripts/scripts.config
    
⁠Logs Not Appearing in Docker
  • Ensure log_mode: both for the script
  • Restart the container if needed:
    docker-compose restart
    

Tag summary

Content type

Image

Digest

sha256:bbead3504…

Size

35.8 MB

Last updated

over 1 year ago

docker pull slipping/alpine-cron