Run Dovecot in a container using the official Docker image. This approach provides isolation and simplified deployment for mail services.
docker pull dovecot/dovecot:latest
docker run -d \
--name dovecot \
-v /path/to/mail:/srv/mail \
-v /path/to/config:/etc/dovecot/conf.d:ro \
-v /path/to/ssl:/etc/dovecot/ssl:ro \
-p 143:143 \
-p 993:993 \
-p 110:110 \
-p 995:995 \
-p 25:25 \
-p 587:587 \
dovecot/dovecot:latest
Create a docker-compose.yml file:
version: '3.8'
services:
dovecot:
image: dovecot/dovecot:latest
container_name: dovecot
restart: unless-stopped
volumes:
# Mail storage
- ./mail:/srv/mail
# Custom configuration (overrides defaults)
- ./config:/etc/dovecot/conf.d:ro
# SSL certificates
- ./ssl:/etc/dovecot/ssl:ro
# Temporary directories
- /tmp:/tmp
- /run:/run
ports:
# IMAP
- "143:143"
- "993:993"
# POP3
- "110:110"
- "995:995"
# SMTP submission
- "587:587"
# LMTP
- "24:24"
environment:
# Default user credentials (change for production)
- USER_PASSWORD=your_secure_hashed_password
# For read-only operation (recommended for security)
read_only: true
security_opt:
- no-new-privileges:true
tmpfs:
- /tmp
- /run
- /var/lib/dovecot
Then deploy:
docker-compose up -d
USER_PASSWORD: Sets the default user password (hashed format recommended)DOVECOT_CONFIG: Path to custom configuration files/srv/mail: Mail storage directory/etc/dovecot/conf.d: Extra configuration files/etc/dovecot/ssl: SSL certificates (default filenames: tls.crt, tls.key)For enhanced security, run the container in read-only mode with temporary filesystems:
docker run -d \
--read-only \
--tmpfs /tmp \
--tmpfs /run \
--tmpfs /var/lib/dovecot \
-v /path/to/mail:/srv/mail \
-v /path/to/config:/etc/dovecot/conf.d:ro \
dovecot/dovecot:latest
latestWhen using Dovecot 2.4.x in containers, note that:
Access container logs:
docker logs dovecot
docker logs dovecot -f # Follow logs
Enter the container for troubleshooting:
docker exec -it dovecot /bin/sh
Add health checks to your Docker Compose file:
healthcheck:
test: ["CMD", "doveadm", "ping"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
Regularly backup your mail storage and configuration:
# Backup mail data
docker run --rm \
-v /path/to/mail:/mail:ro \
-v /backup:/backup \
alpine tar czf /backup/mail-$(date +%Y%m%d-%H%M%S).tar.gz -C /mail .
# Backup configuration
docker run --rm \
-v /path/to/config:/config:ro \
-v /backup:/backup \
alpine tar czf /backup/config-$(date +%Y%m%d-%H%M%S).tar.gz -C /config .