How to install Mautic with Docker on Digital Ocean
Estimated Reading Time: 5 MinutesTable of Contents
Docker is one of the simplest and easiest ways to put an application into production. With Docker, we can launch with a few adjustments a Database server, a Proxy with SSL and then Mautic to carry out all Marketing automation campaigns.
Docker Mautic has had more than 2 million downloads over the past 2 years and is the simplest and safest way to get your mautic up and running.
See more about Docker Mautic at Docker Hub: https://hub.docker.com/r/mautic/mautic/
In this article we will create the entire environment to get Mautic up and running using:
- MySQL
- Free SSL by Let's Encrypt (https://certbot.eff.org/)
- Mautic
- Reverse Proxy with Nginx
An overview of Docker Mautic
The Docker Mautic image was built using the best practices of popular Docker Images on the market to make the perfect environment for Mautic.
The image copies the latest version of Mautic to the /var/www/html folder and configures all necessary permissions on the files.
Along with Mautic we install the Percona MySQL server that has excellent settings for the way in which Mautic works.
Finally, we have a Reverse Proxy that sends requests to Mautic and performs the automatic configuration of SSL with Let's Encrypt and Certbot.
Follow these steps to start using Mautic today:
Step 1: Create a DigitalOcean Droplet
- Access DigitalOcean (or similar VPS provider) and create an account if you don’t have one.
- After logging in, choose 'Create Droplet' with Debian or Ubuntu from the available options
- Choose 2 GB / 50 GB of disk ($10 / month) for small projects
- Choose the location closest to your customer's location
- Activate backups, if necessary (additional charges will apply)
- Login method - Use an SSH key as this is more secure. Otherwise, use a unique password.
- Create the Droplet and wait for it to be provisioned
- Log in with your SSH key or the generated password using the following command:
ssh root@ip
Enter your password as the email sent from DigitalOcean, if you prefer the unique password.
Step 2: Installing Docker on your VPS
It's necessary that the machine be “clean,” do not install any other software like Apache, Nginx, or MySQL on this fresh VPS.
The purpose of the installation script (https://github.com/docker/docker-install) is to facilitate quick installation of the latest versions of Docker-CE on supported linux distributions.
In the Terminal of your server type:
curl -fsSL https://get.docker.com -o get-docker.sh sh get-docker.sh
This will automatically install Docker for you on any supported Linux distribution.
To verify that Docker is working, type:
docker info
You will see your system information.
Getting started with Docker
Docker allows the entire installation process to be automated. Just run a few commands and the software works with the standard configuration and Mautic is no different.
Before you start, you must add the DNS A or CNAME entry on your domain pointing to the IP address of the VPS server on which Mautic will be running.
Step 3 - Setting up a network in Docker
The first step is to create an internal network so that Mautic can communicate with the Database and with the Reverse Proxy. In the terminal type:
docker network create mauticnet
Step 4 - Configure a Reverse Proxy with SSL
We will install the Reverse Proxy called nginx-proxy
next to nginx-proxy-companion
which will be responsible for receiving HTTPs requests and forwarding to Mautic and also creating the free SSL certificate with Let's Encrypt.
In your server's SSH terminal type:
docker run -d --restart=always \ -p 80:80 -p 443:443 --name nginx-proxy \ -v /path/to/certs:/etc/nginx/certs:ro \ -v /etc/nginx/vhost.d \ -v /usr/share/nginx/html \ -v /var/run/docker.sock:/tmp/docker.sock:ro \ --label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy \ --net=mauticnet \ jwilder/nginx-proxy:latest
Now let's install nginx-proxy-companion which is responsible for Let's Encrypt:
docker run -d --restart=always \ --name nginx-proxy-ssl \ -v /path/to/certs:/etc/nginx/certs:rw \ -v /var/run/docker.sock:/var/run/docker.sock:ro \ --volumes-from nginx-proxy \ --net=mauticnet \ jrcs/letsencrypt-nginx-proxy-companion
You already have an nginx server running SSL without modifying any settings. Docker is fantastic.
Step 5: Configuring the MySQL Server
The next commands do the work of installing and configuring MySQL and create a root user for us to use with Mautic:
docker volume create mysql_data docker run --name mysql -d -p 3306:3306 \ -e MYSQL_ROOT_PASSWORD=YOURPASSWORD --restart=always \ -v mysql_data:/var/lib/mysql \ --net=mauticnet \ percona/percona-server:5.7 \ --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
Please modify YOURPASSWORD with a strong password.
Step 6: Configuring Mautic Docker
Finally, we will install Mautic using the official Mautic image that automates the entire installation process:
docker volume create mautic_data docker run -d --restart=always \ --name mautic \ -e MAUTIC_DB_HOST=mysql \ -e MAUTIC_DB_USER=root \ -e MAUTIC_DB_PASSWORD=YOURPASSWORD \ -e MAUTIC_DB_NAME=mautic \ -e VIRTUAL_HOST=mautic.yourdomain.com \ -e LETSENCRYPT_HOST=mautic.yourdomain.com \ -e [email protected] \ -P 8080:80 \ -v mautic_data:/var/www/html \ --net=mauticnet \ --privileged \ mautic/mautic:latest
In the example above, you will need to enter the following variables:
MAUTIC_DB_PASSWORD: Here you must enter the MySQL password.
VIRTUAL_HOST: This is your Mautic's address.
LETSENCRYPT_HOST: You must repeat your Mautic's address;)
LETSENCRYPT_EMAIL: Here is your email to register with Let's Encrypt.
There it is! Now you can visit https://mautic.yourdomain.com.
for step 4, the command is not workink see the message: docker: invalid reference format. See 'docker run --help'. : command not found
For Step 6, "-P 8080:80" wasn't working for me. "-p 8080:80" worked.
me too, -p 8080:80 worked. it was showing the error: Unable to find image '80:80' locally
Hi folks, I've added a warning that we know this article is outdated and we're working on a new one. In the meantime you may wish to check out the repo I've linked to in the warning, because John has been doing a lot of work on simplifying the whole process with Docker Compose.
Thanks Ananda K, working yet in February, 2024