5

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?

2
  • Maybe try to add empty line at and of jobs.txt.
    – jazgot
    Apr 30, 2016 at 17:29
  • @jazgot Yes, empty line at the end is a must, but yet it doesn't solve a problem. Apr 30, 2016 at 19:15

2 Answers 2

4

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

1
0

I have tried every documented solution to this problem, and there is only one that works:

cat /etc/crontab | crontab -

If you already have some entries, you don't want to overwrite them. In that case, do something like this:

(crontab -l 2>/dev/null; cat /etc/crontab ) | crontab -

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .