{"id":21184500,"url":"https://github.com/ajaymahadeven/docker-crons-ofelia-setup-example","last_synced_at":"2026-04-13T03:05:16.468Z","repository":{"id":263289520,"uuid":"868799720","full_name":"ajaymahadeven/docker-crons-ofelia-setup-example","owner":"ajaymahadeven","description":"This repository provides an example setup for using Docker with Ofelia to manage cron jobs. The setup includes a development web server and an Ofelia job runner service.","archived":false,"fork":false,"pushed_at":"2024-10-12T11:49:55.000Z","size":474,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T14:47:34.139Z","etag":null,"topics":["automation","bash","config","crons","debian","devops","docker","docker-image","example","learn","linux","ofelia","scripts","shell"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ajaymahadeven.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-07T07:55:15.000Z","updated_at":"2024-10-15T14:31:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"27615ade-7d11-4254-8a4f-eacc4487d3d4","html_url":"https://github.com/ajaymahadeven/docker-crons-ofelia-setup-example","commit_stats":null,"previous_names":["ajaymahadeven/docker-crons-ofelia-setup-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajaymahadeven%2Fdocker-crons-ofelia-setup-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajaymahadeven%2Fdocker-crons-ofelia-setup-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajaymahadeven%2Fdocker-crons-ofelia-setup-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajaymahadeven%2Fdocker-crons-ofelia-setup-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajaymahadeven","download_url":"https://codeload.github.com/ajaymahadeven/docker-crons-ofelia-setup-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243654399,"owners_count":20325892,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","bash","config","crons","debian","devops","docker","docker-image","example","learn","linux","ofelia","scripts","shell"],"created_at":"2024-11-20T18:09:06.709Z","updated_at":"2026-04-13T03:05:16.441Z","avatar_url":"https://github.com/ajaymahadeven.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker Crons Ofelia Setup Example\n\nThis repository provides an example setup for using Docker with Ofelia to manage cron jobs. The setup includes a development web server and an Ofelia job runner service. This approach is more flexible and maintainable compared to traditional crontab, as it leverages containerization and provides better isolation, easier deployments, and integrated logging.\n\n## Repository Structure\n\n- **docker-compose.yml**: Defines the services and their configurations.\n- **ofelia/config/config.ini**: Configuration file for Ofelia\n- **share/automation**: Cron jobs are placed here (hello.sh for this repo)\n- **share/logs**: Cron job logs are dumped here\n- **share/SQL**: Cron jobs that rely on sql files/execution are placed and sourced from here\n\n## Getting Started\n\n### Prerequisites\n\n- Docker installed on your machine.\n\n### Installation\n\n1. Clone the repository:\n   ```sh\n   git clone https://github.com/thenameisajay/docker-crons-ofelia-setup-example.git\n   cd docker-crons-ofelia-setup-example\n   ```\n\n2. Ensure the `.env` file has the necessary environment variables.\n\n3. Run the Docker services:\n   ```sh\n   docker-compose up -d\n   ```\n\n### Services\n\n#### Development Web Server\n\n- **Container Name**: `dev_php_web`\n- **Image**: `ewalsh200/basephp:7.2.28`\n- **Ports**: Exposes port `80` of the container as `1235` on the host.\n- **Volumes**: Mounts the local `share` directory for file sharing.\n- **Environment**: Loads variables from the `.env` file.\n- **Network**: Connected to `dev_net` with IP `172.12.0.2`.\n\n#### Ofelia Job Runner\n\n- **Container Name**: `ofelia_job_runner`\n- **Image**: `mcuadros/ofelia:latest`\n- **Ports**: Exposes port `8012` of the container as `8509` on the host.\n- **Volumes**: \n  - Mounts Docker socket (`/var/run/docker.sock`) as read-only.\n  - Mounts Ofelia configuration file (`./ofelia/config/config.ini`).\n- **Environment**: \n  - Sets timezone to UTC.\n  - Ensures communication with Docker.\n- **Command**: Starts Ofelia as a daemon with the specified configuration.\n- **Depends On**: Ensures `dev_php_web` service is started before this one.\n- **Network**: Connected to `dev_net` with IP `172.12.0.4`.\n\n### Network Configuration\n\n- **Network Name**: `dev_net`\n- **Driver**: `bridge`\n- **Subnet**: `172.12.0.0/16`\n\n## Usage\n\n### Setting Up the Cron Job (Ofelia)\n\nFollow these steps to configure any .sh script as a cron job:\n\n1. **Edit the Ofelia Configuration File**: Access the configuration file for editing:\n   ```bash\n   cd /ofelia/config\n   nano config.ini\n   ```\n\n2. **Add the Cron Job**: Insert the following line into the configuration file to schedule the hello script to run every minute:\n   ```ini\n   [job-exec \"hello-job\"]\n   schedule = \"@every 1m\"   # Runs every one minute\n   container = \"dev_os\"\n   command = \"/bin/bash /share/automation/hello.sh\"   # Place any cron job under /share/automation/*.sh and change the command \u0026 config options accordingly\n   no-overlap = true\n   ```\n\n   See [Ofelia Jobs](https://github.com/mcuadros/ofelia/blob/master/docs/jobs.md) for more information.\n\n3. **Save and Exit**: Save your changes and exit the editor. The cron job is now configured to run any script that is placed in the `config.ini` automatically.\n\n4. **Restart Ofelia**: Restart the Ofelia service to apply the changes:\n   ```bash\n   docker restart \u003cofelia_container_id or ofelia_container_name\u003e\n   ```\n\n## Screenshots\n\nHere's a visual representation of the setup:\n\n### Development Web Server\n\n![Development Web Server](https://github.com/thenameisajay/docker-crons-ofelia-setup-example/blob/main/screenshots/ofelia-logs.png)\nThis screenshot shows the containers running and ofelia container logs which registers the cron job.\n\n### Ofelia Job Runner\n\n![Ofelia Job Runner](https://github.com/thenameisajay/docker-crons-ofelia-setup-example/blob/main/screenshots/ofelia-logs-1.png)\nThis screenshot displays the Ofelia job runner service in action, starting and managing cron jobs within Docker.\n\n### Cron Logs\n\n![Cron Logs](https://github.com/thenameisajay/docker-crons-ofelia-setup-example/blob/main/screenshots/output.png)\nThis screenshot provides a view of the logs generated by the cron job `hello.sh` managed by Ofelia to run every minute.\n\n\n\n\n## Acknowledgements\n\n- This setup was pieced together from over 20 different websites scattered across the internet. My goal was to create a concise and easy-to-grasp repository.\n- Special thanks to [Ofelia](https://github.com/mcuadros/ofelia) for their excellent tool for managing cron jobs in Docker.\n\n## Contributing\n\nIf you know a **better or more optimal** way to do this setup, please submit a **pull request** with your changes and **an explanation of why it is so**.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajaymahadeven%2Fdocker-crons-ofelia-setup-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajaymahadeven%2Fdocker-crons-ofelia-setup-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajaymahadeven%2Fdocker-crons-ofelia-setup-example/lists"}