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.