0

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

0 Answers0