Skip to content

Nuface Blog

隨意隨手記 Casual Notes

Menu
  • Home
  • About
  • Services
  • Blog
  • Contact
  • Privacy Policy
  • Login
Menu

Enable Logrotate for Dovecot in Docker: Prevent Huge Log Files and Disk Overflow

Posted on 2025-11-152025-11-15 by Rico

When running a self-hosted mail system inside Docker, Dovecot generates a large number of IMAP/POP3/authentication log entries.
If these log files are not rotated properly, they will quickly grow to hundreds of megabytes or even gigabytes, eventually filling up the disk.

This article explains how to correctly configure logrotate for Dovecot running inside a Docker container.


🔧 1. Dovecot Docker Run Command

Example:

docker run -dit --name maildovecot \
    --restart=always \
    --network mail-network \
    --publish 110:110/tcp \
    --publish 995:995/tcp \
    --publish 143:143/tcp \
    --publish 993:993/tcp \
    --publish 24:24/tcp \
    --publish 4190:4190/tcp \
    -v /etc/localtime:/etc/localtime:ro \
    -v /etc/timezone:/etc/timezone:ro \
    -v $PWD/config:/etc/dovecot \
    -v $PWD/log:/var/log \
    -v /opt/docker/mailsys/dovecot/alpine-3.22.1/usermail:/var/vmail \
    -v /opt/docker/wwwapp/data/etc-letsencrypt:/etc/letsencrypt \
    dovecot-alpine:4.0

Important part:

-v $PWD/log:/var/log

Dovecot writes logs to the host machine, so logrotate must be configured on the host, not inside the container.


🔧 2. Create logrotate Configuration

Create the file:

/etc/logrotate.d/dovecot

Content:

/opt/docker/mailsys/dovecot/alpine-3.22.1/ver-4.0/log/dovecot/dovecot-info.log \
/opt/docker/mailsys/dovecot/alpine-3.22.1/ver-4.0/log/dovecot/dovecot.log \
/opt/docker/mailsys/dovecot/alpine-3.22.1/ver-4.0/log/dovecot/sa-learn.log {
    # Rotate daily
    daily

    # Rotate when larger than 50 MB
    size 50M

    # Keep 14 old logs
    rotate 14

    # Compress rotated logs
    compress

    # Delay compression by one cycle
    delaycompress

    # Skip if file does not exist
    missingok

    # Skip if file is empty
    notifempty

    # Copy + truncate without restarting the service
    copytruncate

    sharedscripts
    postrotate
        # Ask Dovecot inside the container to reopen log files
        docker exec maildovecot doveadm log reopen 2>/dev/null || true
    endscript
}

Note:
If you place comments on the same line as commands (e.g., size 50M # comment), logrotate will throw errors such as “unknown unit”.
Always put comments on separate lines.


🔧 3. Test logrotate

logrotate -d /etc/logrotate.conf   # Dry run
logrotate /etc/logrotate.conf      # Execute

You should see:

dovecot.log
dovecot.log.1.gz
dovecot-info.log.1.gz
sa-learn.log.1.gz
...

Log rotation is now working properly.


✔ Recommendation: Disable mail_debug

Unless you are troubleshooting, turn this off:

mail_debug = yes

It massively increases log volume.


🎉 Conclusion

With the above configuration, your Dovecot Docker logs will now:

  • Rotate daily
  • Rotate when exceeding 50MB
  • Compress automatically
  • Keep 14 backups
  • Avoid disk exhaustion
  • Reopen logs without restarting the container

A clean, reliable, and production-grade log management setup.

Recent Posts

  • Postfix + Let’s Encrypt + BIND9 + DANE Fully Automated TLSA Update Guide
  • Postfix + Let’s Encrypt + BIND9 + DANE TLSA 指紋自動更新完整教學
  • Deploying DANE in Postfix
  • 如何在 Postfix 中部署 DANE
  • DANE: DNSSEC-Based TLS Protection

Recent Comments

  1. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on High Availability Architecture, Failover, GeoDNS, Monitoring, and Email Abuse Automation (SOAR)
  2. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on MariaDB + PostfixAdmin: The Core of Virtual Domain & Mailbox Management
  3. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on Daily Operations, Monitoring, and Performance Tuning for an Enterprise Mail System
  4. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on Final Chapter: Complete Troubleshooting Guide & Frequently Asked Questions (FAQ)
  5. Building a Complete Enterprise-Grade Mail System (Overview) - Nuface Blog on Network Architecture, DNS Configuration, TLS Design, and Postfix/Dovecot SNI Explained

Archives

  • December 2025
  • November 2025
  • October 2025

Categories

  • AI
  • Apache
  • Cybersecurity
  • Database
  • DNS
  • Docker
  • Fail2Ban
  • FileSystem
  • Firewall
  • Linux
  • LLM
  • Mail
  • N8N
  • OpenLdap
  • OPNsense
  • PHP
  • QoS
  • Samba
  • Switch
  • Virtualization
  • VPN
  • WordPress
© 2025 Nuface Blog | Powered by Superbs Personal Blog theme