I am trying to build a Debian-based image to dockerize a cron process, but my cron jobs are never started. Here is my Dockerfile:

FROM debian:jessie
RUN apt-get update && apt-get install -y --no-install-recommends cron
COPY jobs.txt /etc/crontab
RUN touch /log.txt
CMD ["cron", "-f"]

...and the jobs.txt file:

* * * * * root echo "job done" >> /log.txt

I realized that there is something wrong with the COPY command, because when I replace

COPY jobs.txt /etc/crontab

with

RUN echo '* * * * * root echo "job done" >> /log.txt' > /etc/crontab

it works perfectly.

So is there a problem just with jobs.txt file and Docker unable to copy it the right way? Should I only fix that file, or use a completely different approach?

  • Maybe try to add empty line at and of jobs.txt. – jazgot Apr 30 '16 at 17:29
  • @jazgot Yes, empty line at the end is a must, but yet it doesn't solve a problem. – Andriy Maletsky Apr 30 '16 at 19:15
up vote 3 down vote accepted

The only difference between using COPY and RUN are the permissions on the /etc/crontab file: with COPY this is 664 and with RUN 644.

I cannot find anything on permissions that /etc/crontab needs to have but if you add

RUN chmod 644 /etc/crontab

after the COPY line in your Dockerfile the cronjobs run (at least for me). So I think the permissions have to be 644

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.