This is inspired by Docker Mailserver, and amend to accomdate our requirements.
Edit docker-compose.yml
to your liking
args:
DEBIAN_VERSION: "11-slim" # postfix 3.5.6
# DEBIAN_VERSION: "10-slim" # postfix 3.4.14
- Install the latest docker-compose
- Edit
docker-compose.yml
to your liking
- substitute
mail
(hostname) andfoo.com
(domainname) according to your FQDN
- If the FQDN is artificial, please do remember add domain name into /etc/hosts
- Configure the mailserver container to your liking by editing mailserver.env (Documentation), but keep in mind this .env file:
- only basic VAR=VAL is supported (do not quote your values!)
- variable substitution is not supported (e.g. 🚫 OVERRIDE_HOSTNAME=$HOSTNAME.$DOMAINNAME 🚫)
Execute the command to build docker image docker-mailserver
docker-compose build
On first start, you will likely see an error stating that there are no mail accounts and the container will exit. You must now do one of two things:
- Use setup.sh to help you: ./setup.sh email add user@domain . You may need the -c option to provide the local path for persisting configuration (a directory that mounts to
/tmp/docker-mailserver
inside the container). This will spin up a new container, mount your configuration volume, and create your first account. - Execute the complete command yourself:
# create mail account user/password
docker run --rm -v "${PWD}/docker-data/dms/config/:/tmp/docker-mailserver/" docker-mailserver setup email add <user@domain> <password>
# list all email accounts
docker run --rm -v "${PWD}/docker-data/dms/config/:/tmp/docker-mailserver/" docker-mailserver setup email list
Make sure to mount the correct configuration directory.
- Execute the command to start container
docker-compose up -d
Any modern desktop mail client installed on the host should be able to connect to this Postfix server, in this example we will use Mozilla Thunderbird.
- Create an (or mutiple) email account which was created in POSTFIX mail server.
- Write an email to the account which was created in POSTFIX mail server.