I am using nginx
in docker. I have configured cron
jobs to update SSL certificates and DNS registration. However the cron
jobs are not running.
What have I done. I have created a Dockerfile
based on arm32v7/nginx
this intern is based on debian:stretch-slim
. At first I installed cron
, and assumed that it would run, but then discovered that the service was not started (there is no init subsystem installed, debian:stretch-slim is very minimal). So I added code to start cron
. Now if I ask the container if cron
is running it says yes.
#ctrl-alt-delor@raspberrypi:~/a_website/docker$
#↳ docker exec -it $(docker container ls | sed -nr -e 's/.*(website-stack.*)/\1/p') service cron status
[ ok ] cron is running.
However I am not seeing any logs from the task that I have added to cron
.
If I run run-parts --report /etc/cron.daily
, the my tasks get run, and produce log output. Therefore it still appears as if cron
is not running.
#ctrl-alt-delor@raspberrypi:~/a_website/docker$
#↳ docker exec -it $(docker container ls | sed -nr -e 's/.*(website-stack.*)/\1/p') cat /proc/12/cmdline; echo
/usr/sbin/cron
So why is cron
not running its jobs? What have I missed?
Dockerfile
FROM arm32v7/nginx
##add backports
COPY stretch-backports-source.list /etc/apt/sources.list.d/
##install cron and curl — so we can register dns regularly
RUN apt-get update &&\
apt-get install -y cron curl &&\
apt-get clean
##setup cron to register dns
COPY register-dns register-dns.auth register-dns-hostname /usr/local/bin/
COPY register-dns.cron /etc/cron.daily/1-register-dns
RUN chmod +x /usr/local/bin/register-dns /etc/cron.daily/1-register-dns
##add curtbot
RUN apt-get update && \
apt-get -t stretch-backports install -y python-certbot-nginx && \
apt-get clean
#add ssl port
EXPOSE 443 80
##custom entry point — needed by cron
COPY entrypoint /entrypoint
RUN chmod +x /entrypoint
ENTRYPOINT ["/entrypoint"]
CMD ["nginx", "-g", "daemon off;"] #:tricky: we seem to need to re-specify this
LABEL name="my-nginx" \
description="nginx + cron + curl + certbot + dns-registering"
entrypoint
#!/bin/sh
## Do whatever you need with env vars here ...
service cron start
# Hand off to the CMD
exec "$@"
/etc/crontab
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
/etc/cron.daily/1-register-dns
#!/bin/sh
date >> /var/log/register-dns
/usr/local/bin/register-dns >>/var/log/register-dns
/var/spool/cron/crontabs
inside the container?/etc/crontab
and/etc/cron.daily/1-reginter-dns
. They are listed in question. The/etc/crontab
it the one that came with the instillation (it is not edited). It looks like it says once per day docd / && run-parts --report /etc/cron.daily
. But it is not doing it. If I type that into the shell, it does it.