How to build a cron docker image properly?
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
Related videos on Youtube
Andrii Maletskyi
Updated on September 18, 2022Comments
-
Andrii Maletskyi over 1 year
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 replaceCOPY 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?-
jazgot about 8 yearsMaybe try to add empty line at and of jobs.txt.
-
Andrii Maletskyi about 8 years@jazgot Yes, empty line at the end is a must, but yet it doesn't solve a problem.
-
-
monty0 over 6 yearsIt's because of the linking that happens in the overlay filesystem. See stackoverflow.com/questions/34962020/…