Sign inSign up

nady5730642/py-cron

By nady5730642

•Updated almost 2 years ago

A lightweight solution to run scheduled Python scripts using custom python script.

Image
Developer tools
0

168

nady5730642/py-cron repository overview

⁠Python Cron Job Scheduler Docker

A lightweight Docker container designed to run Python scripts on a schedule using dcron and environment-configurable cron schedules. This container provides an easy way to set up scheduled tasks with Python, making it ideal for periodic jobs, data processing tasks, automated maintenance, and more.

⁠Features

  • Environment-Based Scheduling: Customize your cron schedule using the CRON_SCHEDULE environment variable, making it easy to update your schedule without modifying the container.
  • Volume-Mounted Scripts: Use Docker volumes to mount your Python script dynamically, allowing you to update or swap scripts without rebuilding the image.
  • Lightweight: Built on python:alpine for minimal resource usage, with dcron for efficient cron scheduling in Docker.
  • Easy Logging: Outputs logs to /var/log/cron.log for easy access to job results and error messages.

⁠Usage

⁠1. Pull the Image
docker pull nady5730642/python-cron
⁠2. Run the Container with Custom Schedule and Script

Replace script.py with your Python script name, and adjust the CRON_SCHEDULE as desired.

docker run -d \
  -e CRON_SCHEDULE="*/10 * * * *" \
  -v $(pwd)/your_script.py:/app/script.py \
  <your-dockerhub-username>/python-cron

This example runs script.py every 10 minutes.

⁠3. Accessing Logs

View the log output of your cron job:

docker logs <container_id>

Or inspect the log file directly:

docker exec -it <container_id> cat /var/log/cron.log

⁠Environment Variables

  • CRON_SCHEDULE: Set this to your desired cron schedule. Default is */5 * * * * (every 5 minutes).
    • Example values:
      • 0 * * * * – Runs every hour.
      • 0 0 * * * – Runs daily at midnight.

⁠Example with Docker Compose

Use the following docker-compose.yml to set up your cron container with a script volume and custom schedule.

version: '3'
services:
  cron-job:
    image: <your-dockerhub-username>/python-cron
    environment:
      - CRON_SCHEDULE=*/15 * * * *  # Runs every 15 minutes
    volumes:
      - ./your_script.py:/app/script.py

Start with:

docker-compose up -d

⁠Notes

  • Ensure your script is executable and uses #!/usr/bin/env python at the top if required.
  • Use absolute paths when defining volumes in Docker Compose or Docker CLI.

⁠License

MIT License. Free to use and modify.

⁠Contributing

Pull requests are welcome! Please make sure to test any changes before submitting.

Tag summary

Content type

Image

Digest

sha256:ed87ee205…

Size

196.3 MB

Last updated

almost 2 years ago

docker pull nady5730642/py-cron