{"id":13552395,"url":"https://github.com/willfarrell/docker-crontab","last_synced_at":"2025-04-06T02:12:25.693Z","repository":{"id":17489550,"uuid":"81764898","full_name":"willfarrell/docker-crontab","owner":"willfarrell","description":"A docker job scheduler (aka. crontab for docker)","archived":false,"fork":false,"pushed_at":"2023-09-12T15:27:58.000Z","size":98,"stargazers_count":307,"open_issues_count":26,"forks_count":67,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-30T01:11:20.944Z","etag":null,"topics":["crontab","docker"],"latest_commit_sha":null,"homepage":null,"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/willfarrell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["willfarrell"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2017-02-12T23:10:48.000Z","updated_at":"2025-03-21T22:25:05.000Z","dependencies_parsed_at":"2024-01-15T15:48:59.526Z","dependency_job_id":"3be12e04-c66a-41ad-8347-d1c0323d5c51","html_url":"https://github.com/willfarrell/docker-crontab","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willfarrell%2Fdocker-crontab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willfarrell%2Fdocker-crontab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willfarrell%2Fdocker-crontab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willfarrell%2Fdocker-crontab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willfarrell","download_url":"https://codeload.github.com/willfarrell/docker-crontab/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423516,"owners_count":20936626,"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":["crontab","docker"],"created_at":"2024-08-01T12:02:03.342Z","updated_at":"2025-04-06T02:12:25.668Z","avatar_url":"https://github.com/willfarrell.png","language":"Shell","readme":"# docker-crontab\n\nA simple wrapper over `docker` to all complex cron job to be run in other containers.\n\n## Supported tags and Dockerfile links\n\n-\t[`latest` (*Dockerfile*)](https://github.com/willfarrell/docker-crontab/blob/master/Dockerfile)\n-\t[`1.0.0` (*Dockerfile*)](https://github.com/willfarrell/docker-crontab/blob/1.0.0/Dockerfile)\n-\t[`0.6.0` (*Dockerfile*)](https://github.com/willfarrell/docker-crontab/blob/0.6.0/Dockerfile)\n\n![](https://img.shields.io/docker/pulls/willfarrell/crontab \"Total docker pulls\") [![](https://images.microbadger.com/badges/image/willfarrell/crontab.svg)](http://microbadger.com/images/willfarrell/crontab \"Get your own image badge on microbadger.com\")\n\n## Why?\nYes, I'm aware of [mcuadros/ofelia](https://github.com/mcuadros/ofelia) (\u003e250MB when this was created), it was the main inspiration for this project. \nA great project, don't get me wrong. It was just missing certain key enterprise features I felt were required to support where docker is heading.\n\n## Features\n- Easy to read schedule syntax allowed.\n- Allows for comments, cause we all need friendly reminders of what `update_script.sh` actually does.\n- Start an image using `image`.\n- Run command in a container using `container`.\n- Run command on a instances of a scaled container using `project`.\n- Ability to trigger scripts in other containers on completion cron job using `trigger`.\n\n## Config file\n\nThe config file can be specifed in any of `json`, `toml`, or `yaml`, and can be defined as either an array or mapping (top-level keys will be ignored; can be useful for organizing commands)\n\n- `name`: Human readable name that will be used as the job filename. Will be converted into a slug. Optional.\n- `comment`: Comments to be included with crontab entry. Optional.\n- `schedule`: Crontab schedule syntax as described in https://en.wikipedia.org/wiki/Cron. Ex `@hourly`, `@every 1h30m`, `* * * * *`. Required.\n- `command`: Command to be run on in crontab container or docker container/image. Required.\n- `image`: Docker images name (ex `library/alpine:3.5`). Optional.\n- `project`: Docker Compose/Swarm project name. Optional, only applies when `contain` is included.\n- `container`: Full container name or container alias if `project` is set. Ignored if `image` is included. Optional.\n- `dockerargs`: Command line docker `run`/`exec` arguments for full control. Defaults to ` `.\n- `trigger`: Array of docker-crontab subset objects. Subset includes: `image`,`project`,`container`,`command`,`dockerargs` \n- `onstart`: Run the command on `crontab` container start, set to `true`. Optional, defaults to falsey.\n\nSee [`config-samples`](config-samples) for examples.\n\n```json\n[{\n \t\"schedule\":\"@every 5m\",\n \t\"command\":\"/usr/sbin/logrotate /etc/logrotate.conf\"\n },{\n \t\"comment\":\"Regenerate Certificate then reload nginx\",\n \t\"schedule\":\"43 6,18 * * *\",\n \t\"command\":\"sh -c 'dehydrated --cron --out /etc/ssl --domain ${LE_DOMAIN} --challenge dns-01 --hook dehydrated-dns'\",\n \t\"dockerargs\":\"--env-file /opt/crontab/env/letsencrypt.env -v webapp_nginx_tls_cert:/etc/ssl -v webapp_nginx_acme_challenge:/var/www/.well-known/acme-challenge\",\n \t\"image\":\"willfarrell/letsencrypt\",\n \t\"trigger\":[{\n \t\t\"command\":\"sh -c '/etc/scripts/make_hpkp ${NGINX_DOMAIN} \u0026\u0026 /usr/sbin/nginx -t \u0026\u0026 /usr/sbin/nginx -s reload'\",\n \t\t\"project\":\"conduit\",\n \t\t\"container\":\"nginx\"\n \t}],\n \t\"onstart\":true\n }]\n```\n\n## How to use\n\n### Command Line\n\n```bash\ndocker build -t crontab .\ndocker run -d \\\n    -v /var/run/docker.sock:/var/run/docker.sock:ro \\\n    -v ./env:/opt/env:ro \\\n    -v /path/to/config/dir:/opt/crontab:rw \\\n    -v /path/to/logs:/var/log/crontab:rw \\\n    crontab\n```\n\n### Use with docker-compose\n\n1. Figure out which network name used for your docker-compose containers\n\t* use `docker network ls` to see existing networks\n\t* if your `docker-compose.yml` is in `my_dir` directory, you probably has network `my_dir_default`\n\t* otherwise [read the docker-compose docs](https://docs.docker.com/compose/networking/)\n2. Add `dockerargs` to your docker-crontab `config.json`\n\t* use `--network NETWORK_NAME` to connect new container into docker-compose network\n\t* use `--rm --name NAME` to use named container\n\t* e.g. `\"dockerargs\": \"--network my_dir_default --rm --name my-best-cron-job\"`\n\n### Dockerfile\n\n```Dockerfile\nFROM willfarrell/crontab\n\nCOPY config.json ${HOME_DIR}/\n\n```\n\n### Logrotate Dockerfile\n\n```Dockerfile\nFROM willfarrell/crontab\n\nRUN apk add --no-cache logrotate\nRUN echo \"*/5 *\t* * *  /usr/sbin/logrotate /etc/logrotate.conf\" \u003e\u003e /etc/crontabs/logrotate\nCOPY logrotate.conf /etc/logrotate.conf\n\nCMD [\"crond\", \"-f\"]\n```\n\n### Logging - In Dev\n\nAll `stdout` is captured, formatted, and saved to `/var/log/crontab/jobs.log`. Set `LOG_FILE` to `/dev/null` to disable logging.\n\nexample: `e6ced859-1563-493b-b1b1-5a190b29e938 2017-06-18T01:27:10+0000 [info] Start Cronjob **map-a-vol** map a volume`\n\ngrok: `CRONTABLOG %{DATA:request_id} %{TIMESTAMP_ISO8601:timestamp} \\[%{LOGLEVEL:severity}\\] %{GREEDYDATA:message}`\n\n## TODO\n- [ ] Have ability to auto regenerate crontab on file change (signal HUP?)\n- [ ] Run commands on host machine (w/ --privileged?)\n- [ ] Write tests\n- [ ] Setup TravisCI\n","funding_links":["https://github.com/sponsors/willfarrell"],"categories":["Shell"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillfarrell%2Fdocker-crontab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillfarrell%2Fdocker-crontab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillfarrell%2Fdocker-crontab/lists"}