Install Matomo Inside Docker Container in Linux

Install Matomo Inside Docker Container in Linux

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 \

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 \

MySQL container should run on the same user-defined bridge network as well.


  • The MATOMO_DATABASE_USERNAME and MATOMO_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.

Matomo Inside Docker Container in Linux

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:

Matomo trusted hosts warning

In the configuration file, add hostname or IP address with port as trusted host:

sudo sed -i '/^\[General\]/a trusted_hosts[] = ""' /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

Your email address will not be published.