Matomo (formerly known as Piwik) is a web analytics platform that allows tracking visits, page views, and other statistics on the website. Matomo is an open-source alternative to Google Analytics.
This tutorial explains how to install Matomo inside a Docker container in the Linux. Commands have been tested on Ubuntu.
Prepare environment
Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.
You also need to have a running MySQL container. Instructions can be found in the post.
Install Matomo
Before starting, create matomo
database:
docker exec -it mysql mysql -u root -p -e "CREATE DATABASE matomo"
- Host network
Run the following command to create a container for Matomo that uses host network:
docker run -d --name=matomo --restart=always --network=host \
-v /opt/matomo/data:/var/www/html \
-e MATOMO_DATABASE_USERNAME=root \
-e MATOMO_DATABASE_PASSWORD=pwd123 \
-e MATOMO_DATABASE_DBNAME=matomo \
-e MATOMO_DATABASE_HOST=127.0.0.1 \
matomo
MySQL container should run on host network as well.
- User-defined bridge network
User-defined bridge network can be used for listening on different port. By default, Matomo service is listening on port 80. It can be changed with -p
option.
docker network create app-net
docker run -d --name=matomo --restart=always --network=app-net \
-p 8080:80 \
-v /opt/matomo/data:/var/www/html \
-e MATOMO_DATABASE_USERNAME=root \
-e MATOMO_DATABASE_PASSWORD=pwd123 \
-e MATOMO_DATABASE_DBNAME=matomo \
-e MATOMO_DATABASE_HOST=mysql \
matomo
MySQL container should run on the same user-defined bridge network as well.
Notes:
- The
MATOMO_DATABASE_USERNAME
andMATOMO_DATABASE_PASSWORD
can be used to specify MySQL credentials. - When user-defined bridge network is used, don't forget to change
MATOMO_DATABASE_HOST
. It specifies MySQL container name.
Testing Matomo
Open a web browser and go to http://<IP_ADDRESS>
, where <IP_ADDRESS>
is the IP address of the system. Follow steps to complete installation. For the first time, you will be asked to create the superuser. After that, you will be redirected to a page to log in to the dashboard.
Note: if a different port is used than 80, then additional configuration is required after completing installation steps. You will get the following warning at the top of the page:
In the configuration file, add hostname or IP address with port as trusted host:
sudo sed -i '/^\[General\]/a trusted_hosts[] = "192.168.0.252:8080"' /opt/matomo/data/config/config.ini.php
Restart Docker container:
docker restart matomo
Uninstall Matomo
To completely remove Matomo, remove its container:
docker rm --force matomo
Remove Matomo image:
docker rmi matomo
You can also remove Matomo data:
sudo rm -rf /opt/matomo
If a user-defined bridge network was created, you can delete it as follows:
docker network rm app-net
Leave a Comment
Cancel reply