Logrotate - nginx logs not rotating inside docker container
As stated on the edit on my question the problem was that CMD
from nginx:1.11
was only starting the nginx
process. A work around is to place the following command on my Dockerfile
CMD service cron start && nginx -g 'daemon off;'
This will start nginx as nginx:1.11
starts it and well as start the cron service.
The Dockerfile would look something like:
FROM nginx:1.11
# Remove sym links from nginx image
RUN rm /var/log/nginx/access.log
RUN rm /var/log/nginx/error.log
# Install logrotate
RUN apt-get update && apt-get -y install logrotate
# Copy MyApp nginx config
COPY config/nginx.conf /etc/nginx/nginx.conf
#Copy logrotate nginx configuration
COPY config/logrotate.d/nginx /etc/logrotate.d/
# Start nginx and cron as a service
CMD service cron start && nginx -g 'daemon off;'
i found a method from this link, its core idea is use logrotate
outside, and conf is as below:
$ sudo vi /etc/logrotate.d/test
/home/test/logs/*log {
rotate 90
missingok
ifempty
sharedscripts
compress
postrotate
/usr/bin/docker exec nginx-test /bin/sh -c '/usr/sbin/nginx -s reopen > /dev/null 2>/dev/null'
endscript
}