A lightweight solution to run scheduled Python scripts using custom python script.
168
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.
CRON_SCHEDULE environment variable, making it easy to update your schedule without modifying the container.python:alpine for minimal resource usage, with dcron for efficient cron scheduling in Docker./var/log/cron.log for easy access to job results and error messages.docker pull nady5730642/python-cron
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.
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
CRON_SCHEDULE: Set this to your desired cron schedule. Default is */5 * * * * (every 5 minutes).
0 * * * * – Runs every hour.0 0 * * * – Runs daily at midnight.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
#!/usr/bin/env python at the top if required.MIT License. Free to use and modify.
Pull requests are welcome! Please make sure to test any changes before submitting.
Content type
Image
Digest
sha256:ed87ee205…
Size
196.3 MB
Last updated
almost 2 years ago
docker pull nady5730642/py-cron