/ mailtrain

Deploy Mailtrain With Docker

The steps below show you how to deploy a minimal Mailtrain server (an open source Mailchimp alternative) on Ubuntu 16.04 LTS. This will not be using a dockerized Redis or MySQL server so you can get by with just a 512MB RAM instance.

Steps

Make sure you are running the latest LTS kernel, and if not upgrade it.

Install docker.

Install docker-compose.

Deploy a MySQL or MariaDB server (may or may not be on the same server). This will hold all of our "state" that will be kept across mailtrain deployments.

Download the latest release. At the time of writing this post, it is 1.23.2, but be sure to check and update the command below accordingly.

wget https://github.com/Mailtrain-org/mailtrain/archive/v1.23.2.tar.gz
tar --extract --gzip --file v1.23.2.tar.gz
rm v1.23.2.tar.gz

Now we have to do a few extra steps to ensure we are using the local files in the docker build, rather than always cloning the latest.

mkdir mailtrain
mv mailtrain-1.23.2 mailtrain/app
mv mailtrain/app/Dockerfile mailtrain/.

# Update the dockerfile
SEARCH="RUN git clone git://github.com/Mailtrain-org/mailtrain.git /app"
REPLACE="COPY app /app"
FILEPATH="mailtrain/Dockerfile"
sed -i "s;$SEARCH;$REPLACE;" $FILEPATH

Navigate to within the mailtrain folder.

cd mailtrain*

Build the container with:

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: '2'
services:
  mailtrain-node:
    image: mailtrain-node:latest
    container_name: "mailtrain-node"
    restart: always
    ports:
      - "80:3000"
    volumes:
      - "./volumes/production.toml:/app/config/production.toml"
      - "./volumes/mailtrain-node-data:/app/public/grapejs/uploads"
      - "./volumes/mailtrain-node-data:/app/public/mosaico/uploads"

Create a folder called volumes.

mkdir volumes

Copy the default toml config file into your volumes folder to be used.

cp mailtrain/app/config/default.toml \
volumes/production.toml

Update MySQL credentials in the config file you just created.

editor production.toml
...
[mysql]
host="MYSQL_HOSTNAME"
user="mailtrain"
password="MYSQL_USER_PASSWORD"
database="mailtrain"
port=3306
charset="utf8mb4"
timezone="UTC"

...

[redis]
enabled=false
...

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.

References

Stuart Page

Stuart Page

Stuart is a software developer with a passion for Linux and open source projects.

Read More