A lightweight Docker image based on Alpine Linux for running cron jobs and startup commands with automatic log rotation.
- Based on Alpine Linux 3.18
- Runs cron jobs defined through environment variables
- Executes startup commands
- Automatic log rotation using logrotate
- Real-time log output
docker run -d \
-e CRON_JOB_EXAMPLE1="* * * * * echo 'Hello, World!'" \
-e CRON_JOB_EXAMPLE2="0 2 * * * echo 'Hourly task'" \
-e STARTUP_COMMAND_EXAMPLE1="echo 'Container started!'" \
-e STARTUP_COMMAND_EXAMPLE2="echo 'Initializing services...'" \
-e STARTUP_CONDITION="curl -s http://localhost:3000" \
monlor/docker-cron:main
CRON_JOB_<name>
: Define cron jobs. Format:"<schedule> <command>"
STARTUP_COMMAND_<name>
: Define commands to run at container startupSTARTUP_CONDITION
: Define a condition that must be met before starting services
Cron jobs are added to the container's crontab. The format is:
RON_JOB_<name>="<schedule> <command>"
Example:
CRON_JOB_HELLO="* * * * * echo 'Hello, World!'"
CRON_JOB_BACKUP="0 2 * * * curl -sSf https://example.com/api/backup"
Startup commands are executed at container startup. The format is:
STARTUP_COMMAND_<name>="<command>"
Example:
STARTUP_COMMAND_INIT="echo 'Initializing...'"
STARTUP_COMMAND_CONFIG="curl -sSf https://example.com/api/config"
You can set a startup condition that must be met before the container starts its services. This is useful for ensuring dependencies are ready. The format is:
STARTUP_CONDITION="<command>"
Example:
STARTUP_CONDITION="curl -sSf https://example.com/api/health &> /dev/null"
- Logs are stored in
/var/log/cron/
and/var/log/
- Log rotation is configured to:
- Rotate files when they reach 10MB
- Keep 5 rotated log files
- Compress old log files
To build the Docker image:
docker build -t your-image-name .
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.