cron - Inside Docker container, cronjobs are not getting executed -
i have made docker image, dockerfile, , want cronjob executed periodically when container based on image running. dockerfile (the relevant parts):
from l3iggs/archlinux:latest copy source /srv/visitor workdir /srv/visitor run pacman -syyu --needed --noconfirm \ && pacman -s --needed --noconfirm make gcc cronie python2 nodejs phantomjs \ && printf "*/2 * * * * node /srv/visitor/visitor.js \n" >> cronjobs \ && crontab cronjobs \ && rm cronjobs \ && npm install -g node-gyp \ && python=/usr/sbin/python2 && export python \ && npm install expose 80 cmd ["/bin/sh", "-c"]
after creation of image run container , verify indeed cronjob has been added:
crontab -l */2 * * * * node /srv/visitor/visitor.js
now, problem cronjob never executed. have, of course, tested "node /srv/visitor/visitor.js" executes when run manually console.
any ideas?
it's little tricky answer definitively, don't have time test, have various options open you:
you use phusion base image, comes init system , cron installed. based on ubuntu , comparatively heavyweight (at least compared archlinux) https://registry.hub.docker.com/u/phusion/baseimage/
if you're happy have started cron jobs, start cron
cmd
, keep in foreground (cron -f
).you can use lightweight process manager start cron , whatever other processes need (phusion use runit, docker seem recommend supervisor).
you write own
cmd
orentrypoint
script starts cron , process. issue need careful handle signals or may end zombie processes.
in case, if playing around, i'd go last option, if it's more serious, i'd go process manager.
Comments
Post a Comment