-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logrotate #1455
Comments
You can use logrotate with the "copytruncate" option. FROM alpine:latest
ENV CRON="*/30 * * * *"
RUN apk --update add logrotate
RUN echo "${CRON} /usr/sbin/logrotate -v /etc/logrotate.conf" >> /etc/crontabs/root && \
mkdir -p /etc/logrotate.d && \
echo "/var/log/nginx/*.log" > /etc/logrotate.d/nginx && \
echo "{" >> /etc/logrotate.d/nginx && \
echo " dateext" >> /etc/logrotate.d/nginx && \
echo " dateformat -%Y-%m-%d-%s" >> /etc/logrotate.d/nginx && \
echo " size 10M" >> /etc/logrotate.d/nginx && \
echo " compress" >> /etc/logrotate.d/nginx && \
echo " missingok" >> /etc/logrotate.d/nginx && \
echo " notifempty" >> /etc/logrotate.d/nginx && \
echo " copytruncate" >> /etc/logrotate.d/nginx && \
echo " rotate 10" >> /etc/logrotate.d/nginx && \
echo "}" >> /etc/logrotate.d/nginx
CMD ["crond", "-f"] docker-compose version: '2.2'
services:
logrotate:
build:
context: .
dockerfile: Dockerfile.logrotate
container_name: nginx-logrotate
restart: always
volumes:
- ./data/logs:/var/log/nginx
stop_grace_period: 1s |
I finally use the logrotate on the host. Nginx logs are a mount volume.
I hope that can help others. Maybe this can be copy on some kind of wiki ? |
I want to try the solution proposed by @ghostiam but I can't find how to send kill -USR1 to nginx to rotate the logs. Nginx and Logrotate are not in the same container. |
@Bob-le-pirate With "copytruncate" option you don't need use kill -USR1 |
Features Requests
Is that possible to add an environnement variable to enable logrotate ?
I see defaults config files are already present in
/etc/logrotate.d
Of course I can create another container to do that, but in this case I need the docker socket to send USR1 to nginx (https://nginx.org/en/docs/control.html). What's your opinion ?
Azlux
The text was updated successfully, but these errors were encountered: