Bootstrap FreeKB - Docker Mailserver (Email) - Install Postfix Dovecot mailserver on Docker
Docker Mailserver (Email) - Install Postfix Dovecot mailserver on Docker

Updated:   |  Docker Mailserver (Email) articles

AVOID TROUBLE

Ensure your Docker servers have at least 2 GB of available memory.

Create the docker-compose.yml file with the following, replacing hostname and domainname.

version: '3'
services:
  mailserver:
    image: docker.io/mailserver/docker-mailserver:latest
    container_name: mailserver
    hostname: mail.example.com
    domainname: example.com
    ports:
      - "25:25"
      - "143:143"
      - "587:587"
      - "993:993"
    volumes:
      - /usr/local/docker/mailserver/mail-data/:/var/mail/
      - /usr/local/docker/mailserver/mail-state/:/var/mail-state/
      - /usr/local/docker/mailserver/mail-logs/:/var/log/mail/
      - /usr/local/docker/mailserver/config/:/tmp/docker-mailserver/
      - /etc/localtime:/etc/localtime:ro
    environment:
      - ENABLE_SPAMASSASSIN=1
      - SPAMASSASSIN_SPAM_TO_INBOX=1
      - ENABLE_CLAMAV=1
      - ENABLE_FAIL2BAN=1
      - ENABLE_POSTGREY=1
      - ENABLE_SASLAUTHD=0
      - ONE_DIR=1
      - DMS_DEBUG=0
      - PERMIT_DOCKER=host
    cap_add:
      - NET_ADMIN
      - SYS_PTRACE
    restart: always

 

Use the docker-compose up command with the -d or --detach flag to create the container.

sudo docker-compose up --detach

 

The docker container ls command should show that the container is up and running.

~]$ sudo docker container ls
CONTAINER ID   IMAGE                                 COMMAND                  CREATED          STATUS          PORTS                                                                                                                                                                                         NAMES
8198fb45872c   mailserver/docker-mailserver:latest   "/usr/bin/dumb-init …"   29 minutes ago   Up 29 minutes   0.0.0.0:25->25/tcp, :::25->25/tcp, 110/tcp, 0.0.0.0:143->143/tcp, :::143->143/tcp, 0.0.0.0:587->587/tcp, :::587->587/tcp, 465/tcp, 995/tcp, 0.0.0.0:993->993/tcp, :::993->993/tcp, 4190/tcp   mailserver

 

Issue the following command to create your first users email accounts.

sudo docker run --rm --volume "/usr/local/docker/mailserver/config/:/tmp/docker-mailserver/" mailserver/docker-mailserver setup email add <user@domain> <password>

 

The docker logs command should return something like this.

~]# sudo docker logs mailserver
[ TASKLOG ]  Starting daemons & mail server
cron: started
rsyslog: started
dovecot: started
update-check: started
opendkim: started
opendmarc: started
postgrey: started
postfix: started
fail2ban: started
clamav: started
changedetector: started
amavis: started
[ TASKLOG ]  mail.example.com is up and running

 

The docker exec command can be used to validate that your users email account exists.

~]$ sudo docker exec mailserver setup email list
* john.doe@example.com ( 0 / ~ ) [0%]

 

Send the user an email.

sudo docker exec mailserver echo "Hello World" | mail -s "Example Subject" -r no-reply@example.com john.doe@example.com

 

And now this command should contain something like this, showing 2.0K of emails in this example.

~]$ sudo docker exec mailserver setup email list
* john.doe@example.com ( 2.0K / ~ ) [0%]

 

In the container, the /var/mail/domain/user/new directory should contain the users emails.

~]$ sudo docker exec mailserver ls -l /var/mail/example.com/john.doe/new
-rw-r--r-- 1 docker docker 1216 Mar 18 09:48 1647614891.M334214P1512.mail.example.com,S=1216,W=1244

 

On the Docker host, the docker-data/dms/mail-data/domain/user/new directory should also contain the users emails.

~]$ ll docker-data/dms/mail-data/example.com/john.doe/new/
-rw-r--r-- 1 5000 5000 1216 Mar 18 09:48 1647614891.M334214P1512.mail.example.com,S=1216,W=1244

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


October 12 2022 by archlinuxuser
If IPV6 is not configured, I see error:mailserver | Oct 12 07:26:16 mail dovecot: master: Fatal: Failed to start listeners mailserver | Oct 12 07:26:17 mail dovecot: master: Error: socket() failed: Address family not supported by protocol mailserver | Oct 12 07:26:17 mail dovecot: master: Error: service(imap-login): listen(::, 143) failed: Address family not supported by protocol mailserver | Oct 12 07:26:17 mail dovecot: master: Error: socket() failed: Address family not supported by protocol mailserver | Oct 12 07:26:17 mail dovecot: master: Error: service(quota-status): listen(::, 65265) failed: Address family not supported by protocol

Add a Comment


Please enter 799792 in the box below so that we can be sure you are a human.