Deploy Mailtrain v1 With Docker
Mailtrain went through a major update to v2 (deployment instructions), so this is a place for me to move/archive the original instructions I created for deploying Mailtrain (v1).
The steps below show you how to deploy a minimal Mailtrain server (an open source Mailchimp alternative) on Ubuntu 18.04 LTS.
Minimum Requirements
- 1 GB of RAM
- Preferably a 1GB swap file (create one)
Steps
Make sure you are running Ubuntu 18.04 with the latest LTS kernel, and if not upgrade it.
Download the latest release. At the time of writing this post, it is 1.24.0, but be sure to check and update the command below accordingly.
wget https://github.com/Mailtrain-org/mailtrain/archive/v1.24.1.tar.gz
tar --extract --gzip --file v1.24.1.tar.gz
rm v1.24.1.tar.gz
Navigate to within the mailtrain folder and build the image.
cd mailtrain-*
sudo docker build -t mailtrain-node:latest .
Navigate back home.
cd ~
Copy and paste the content below into a file called docker-compose.yml
.
version: '3'
services:
mailtrain-node:
image: mailtrain-node:latest
container_name: "mailtrain-node"
restart: always
ports:
- "80:3000"
volumes:
- $HOME/volumes/mailtrain/production.toml:/app/config/production.toml
- $HOME/volumes/mailtrain/mailtrain-node-data:/app/public/grapejs/uploads
- $HOME/volumes/mailtrain/mailtrain-node-data:/app/public/mosaico/uploads
database:
image: mariadb
container_name: db
restart: always
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_DATABASE: mailtrain
MYSQL_USER: mailtrain
MYSQL_PASSWORD: mymailtrainpassword
volumes:
- $HOME/volumes/mysql/data:/var/lib/mysql
Create a folder called volumes.
mkdir -p $HOME/volumes/mailtrain/
Copy the default toml config file into your volumes folder to be used.
cp $HOME/mailtrain-1.24.1/config/default.toml \
$HOME/volumes/mailtrain/production.toml
Update MySQL credentials in the config file you just created.
editor $HOME/volumes/mailtrain/production.toml
...
[mysql]
host="db"
user="mailtrain"
password="mymailtrainpassword"
database="mailtrain"
...
[redis]
enabled=false
...
host
field for it to work with the docker container.
You will also need to ensure your MySQL server allows remote connections by commenting out the bind-address
line in the /etc/mysql/mysql.conf.d/mysqld.cnf
config file.
Now deploy the docker containers with:
docker-compose up -d
Conclusion
You now have a working mailtrain server. Be sure to open your web browser to the ip or hostname of your server and authenticate with admin
: test
before going to the settings area to change your login credentials, and plug in your SMTP or AWS SES credentials for sending emails.
Optional - Exposing The Database
If you want to be able to access the database remotely, add the ports
line to the docker-compose file for the database like so:
version: '3'
services:
mailtrain-node:
image: mailtrain-node:latest
container_name: "mailtrain-node"
restart: always
ports:
- "80:3000"
volumes:
- $HOME/volumes/mailtrain/production.toml:/app/config/production.toml
- $HOME/volumes/mailtrain/mailtrain-node-data:/app/public/grapejs/uploads
- $HOME/volumes/mailtrain/mailtrain-node-data:/app/public/mosaico/uploads
database:
image: mariadb
container_name: db
restart: always
ports:
- 3306:3306
environment:
# @see https://phabricator.wikimedia.org/source/mediawiki/browse/master/includes/DefaultSettings.php
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_DATABASE: mailtrain
MYSQL_USER: mailtrain
MYSQL_PASSWORD: mymailtrainpassword
volumes:
- $HOME/volumes/mysql/data:/var/lib/mysql
mymailtrainpassword
to something random nobody will know, in both this config and the production.toml
file.
References
First published: 3rd August 2021