Score:0

inside nginx custom docker image, cron service is running but not the jobs executing

dm flag

Dockerfile of nginx container

FROM nginx:latest

# Remove sym links from nginx image
RUN rm /var/log/nginx/access.log
RUN rm /var/log/nginx/error.log

RUN apt-get update && apt-get install -y logrotate && rm -rf /var/lib/apt/lists/*

COPY nginx.conf /etc/nginx/nginx.conf
# COPY conf.d /etc/nginx/conf.d
# COPY cert/ /etc/nginx/certs
COPY data /data
COPY --chown=root:root nginx /etc/logrotate.d/
RUN echo -e '#!/bin/sh\nlogrotate -f /etc/logrotate.d/nginx\n' > /etc/cron.daily/logrotate-nginx && chmod +x /etc/cron.daily/logrotate-nginx


EXPOSE 80 443
CMD service cron start && nginx -g 'daemon off;'

cron service running

root@f11ddfdb471a:/# service cron status
cron is running.

crontab

*/1  *  *  *  *   root    /usr/sbin/logrotate /etc/logrotate.d/nginx
* * * * * echo "Hello world!" >> /var/log/cron.log 2>&1

empty log

root@f11ddfdb471a:/# cat /var/log/cron.log
root@f11ddfdb471a:/# cat /var/log/cron.log

the issue is not just with the single job, i also have logrotate which is also not being triggered

What i tried

  1. Manually started cron service and restarted multiple time as well the nginx container
  2. if i run those jobs manually, they just work fine

Solution

@AlexeyTen, infact you are right,

the second job is missing the root user and the first job having the script permissions as 664 instead of 644

br flag
You’ve missed `root` in second line of crontab
Rajsekar Reddy avatar
dm flag
yes, but the first job is also not running, that is the issue
Rajsekar Reddy avatar
dm flag
@AlexeyTen, infact you are right, the second job is missing the root user and the first job having the script permissions as 664 instead of 644
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.