To get started with Matomo on Docker, you'll need to have Docker installed on your machine.
You can download and install Docker from the official Docker website.
First, pull the Matomo image from the Docker Hub registry.
You can do this by running the command `docker pull matomo/matomo:latest` in your terminal.
Installation
To install Matomo using Docker, you'll need to start by creating a Debian 9.6 (Stretch) server. This is the base system that will run Docker and Matomo.
The next step is to create a user on the server. This user will be used to run Docker and Matomo.
You'll also need to create the Docker files in the user's home directory. This will allow Docker to run with the correct permissions.
After that, you'll need to create a systemd entry. This will allow Docker to start automatically when the server boots.
Finally, you'll need to configure the frontend web server. This will allow Matomo to be accessed from outside the server.
To find out which port is being used, look at the last line of the docker-compose.yml file. This file maps the internal port 80 of the frontend Nginx to the external port 8081 of the host.
Here's a summary of the steps to install Matomo:
- Create a user on the server.
- Create the Docker files in the user's home directory.
- Create a systemd entry.
- Configure the frontend web server.
Configuring Setup
To configure Matomo's setup, start by clicking "Hosts" at the top of the page and then "Add Proxy Host".
Enter your domain name in the first text box. I've entered analytics.dbtech.xyz into the first text box.
Enter your server's local IP address in the "Forward Hostname / IP" box and enter 8384 into the "Forward Port" box.
Next, go to the "SSL" tab and select the "Request a New SSL" option in the dropdown. Also, check the "Force SSL" and "HTTP/2 Support" options.
After a moment or so, the page should reload and there should be a new entry on your Proxy Hosts page.
Click the URL under the SOURCE column and it should take you to your new installation of Matomo in a new browser tab.
If everything worked and you're able to see analytics.your-domain.com, then we need to make a couple more changes.
To edit the SSL settings, go back to NGINX Proxy Manager and find your new entry. Click the 3 vertical dots on the right side of the page next to your new entry.
Click "Edit" and re-check the 2 radio buttons for "Force SSL" and "HTTP/2 Support".
Now you can go back to analytics.your-domain.com and go through the installation process.
Features and Usage
The Matomo Docker image has some fantastic features that make it a breeze to use. You can run it as a non-root user, which is a big plus for security.
One of the standout features is the ability to keep plugins and config across upgrades of the image. This means you don't have to worry about losing your customizations when you update the image.
The image also includes Redis enabled and ready to enhance server performance. Plus, it has OPCache enabled to store precompiled script bytecode in shared memory. This should give your Matomo instance a nice speed boost.
Here are some of the key features at a glance:
- Run as non-root user
- Multi-platform image
- Config, plugins and user preferences in the same folder
- Unifont for languages using unicode characters
- Cron tasks to archive Matomo reports as a "sidecar" container
- Plugins and config are kept across upgrades of this image
- OPCache enabled to store precompiled script bytecode in shared memory
- Redis enabled and ready to enhance server performance
- s6-overlay as process supervisor
- Traefik as reverse proxy and creation/renewal of Let's Encrypt certificates
- msmtpd SMTP relay image to send emails
- Redis Docker image ready to use as Redis cache or QueuedTracking plugin
- MariaDB Docker image as database instance
- geoip-updater Docker image to download MaxMind's GeoIP2 databases
- Cron jobs as a "sidecar" container
Just a heads up: you'll need to have your own database server set up to connect to, as this image only runs Matomo.
Features
The features of this system are quite impressive. It can run as a non-root user, which is a great security feature.
This means you don't have to worry about compromising the entire system if you need to make changes or updates.
One of the standout features is the ability to run on multiple platforms, making it a versatile choice for different environments.
You can also configure, plugins, and user preferences in the same folder, which makes it easy to manage and keep track of everything.
This includes the use of Unifont for languages that use Unicode characters, which is a great feature for international users.
Cron tasks can be used to archive Matomo reports as a "sidecar" container, which is a convenient way to keep track of your data.
You can also pass additional options during cron archive, giving you more control over the process.
Plugins and config are kept across upgrades of this image, so you don't have to worry about losing your customizations.
OPCache is enabled to store precompiled script bytecode in shared memory, which can improve performance.
Redis is also enabled and ready to enhance server performance, making it a great choice for high-traffic sites.
The system uses s6-overlay as a process supervisor, which helps keep everything running smoothly.
Traefik is used as a reverse proxy and can even create and renew Let's Encrypt certificates for you.
msmtpd is a SMTP relay image that can be used to send emails, which is a useful feature for notifications and other automated tasks.
The system also includes a Redis Docker image that can be used as a cache or with the QueuedTracking plugin for better scalability.
A MariaDB Docker image is included as a database instance, which is a great choice for storing and managing data.
Finally, the geoip-updater Docker image can be used to download MaxMind's GeoIP2 databases on a time-based schedule for geolocation.
Here are the features listed out in a table for easy reference:
Usage
To use Matomo effectively, you will need to have your own database server to connect to, as it only runs on Matomo.
Having a self-hosted database server gives you full control over your data and allows you to tailor Matomo to your specific needs.
You can't use Matomo as a standalone solution, it requires a connection to your own database server.
Features and Usage
To enable the cron job in Matomo, you have to run a "sidecar" container. This can be done by defining a sidecar container called matomo_cron, with the same image as matomo and possibly the same volumes, with an entrypoint script that essentially does two things: trivially defines a cron job on the host system.
The cron job can also be enabled by running a simple container like this: docker run -d --name matomo_cron --volumes-from matomo --entrypoint /cron.sh matomo. This will create a new container that runs the cron job.
If you have enabled CRON_ARCHIVE to automatically archive the reports, you have to disable Matomo archiving to trigger from the browser. Go to System > General settings.
To disable Matomo archiving, you'll need to navigate to the System > General settings page.
Sources
- https://github.com/crazy-max/docker-matomo
- https://blog.clemlatz.dev/blog/how-to-run-matomo-in-a-docker-container-while-passing-database-credentials-as-environment-variables/
- https://davquar.it/post/self-hosting/matomo-docker/
- https://dbtechreviews.com/2021/02/12/matomo-self-hosted-google-analytics-alternative-on-docker/
- https://software-berater.net/2019/matomo-mit-docker/
Featured Images: pexels.com