Public | Automated Build

Last pushed: a year ago
Short Description
Run Cron jobs inside Docker container
Full Description

Docker-Cron

Use Cron inside Docker. Looks for crontab at /cron/crontab

Note: Does not use actual cron binary, as there are issues running it inside Docker.
Uses devcron instead.

Use

This example mounts the folder containing your crontab file. Presumably you would
put your scripts in the same file and reference them in your crontab as /cron/myscript.sh

$ docker run -v /host/folder/containing/crontab:/cron -d hamiltont/docker-cron

This example mounts two folders, one with the crontab and one with the scripts. You need
to use /scripts/myscript.sh in your crontab

$ docker run -v /host/folder/containing/crontab:/cron -v /host/folder/scripts:/scripts -d hamiltont/docker-cron
Docker Pull Command
Owner
hamiltont
Source Repository

Comments (6)
abbr
7 months ago

@hamiltont, thanks for providing this image. I am looking for a docker cron image runnable on OpenShift, which forbidding container process running as root. Your image is the only one compatible I can find. Keep up the good work!

gavinjonespf
a year ago

@jeverling:
Another issue you may encounter with cron and overlayfs:
https://github.com/docker/docker/issues/16813
https://github.com/phusion/baseimage-docker/issues/198

Basically, cron fails hard on hardlinks, which are common in overlayfs setup. Still looking at a better solution, but using devcron is workable.

jeabakker
a year ago

I have a small question/issue.

I've configured a daily cron job, but it runs at GMT 0:00 instead of my local timezone (CEST) 0:00.
Is there a way I can change this (without having to configure the crontab to run at an offset)

ggtools
2 years ago

The main issues with the official cron is that it requires an environment to run a syslog daemon and a mail daemon for instance.

hamiltont
3 years ago

@jeverling - to be frank I don't remember what was going wrong. I think it had to do with cron requiring other system components to be running, but that may be incorrect. See http://programster.blogspot.com/2014/01/docker-working-with-cronjobs.html for someone else with problems just directly running cron in the foreground. FWIW, I'd love to just run cron in the container, this image also seems like a hack to me, but it's a hack that works and I just wanted something that got the job done when I made it. If you find a better container please comment here so I''m aware of it too :)

jeverling
3 years ago

Hi, and thanks a lot for this image! Could you elaborate a bit on the issues you encountered when running the cron binary inside Docker? devcron works nice, but having to install mercurial and using a base-image with pip seems to be a lot of stuff for projects where Python isn't used otherwise.