Running Matomo Using Docker Compose

Recently, I need to quickly set up Matomo to track visits on my website. This is the blueprint you can use to quickly get Matomo up and running with docker-compose.

The YAML file

The YAML file contains two services. One is for Matomo itself. The other is the database. Here, I select MariaDB to run as the app’s database.

Both refer to an environment file containing environment variables for both services.

version: "3"

services:
  matomo_db:
    image: mariadb:10.6
    container_name: matomo_db
    command: --max-allowed-packet=64MB
    restart: always
    volumes:
      - /app/data/matomo/db:/var/lib/mysql
    env_file: 
      - ./matomo.env 

  matomo_app:
    image: matomo:4.5.0-apache
    container_name: matomo_app
    restart: always
    depends_on: 
      - matomo_db
    volumes:
      - /app/data/matomo/web:/var/www/html

    env_file: 
      - ./matomo.env 

    ports:
      - 127.0.0.1:28080:80

Make sure to map the volume to both MariaDB and Matomo or you will lose your data, which is undesirable.

Env file

As mentioned above, this is the environment file for both Matomo and MariaDB.

MYSQL_ROOT_PASSWORD=npL4VEBERKGgirs44
MYSQL_DATABASE=matomo_tracking
MATOMO_DATABASE_HOST=matomo_db
MATOMO_DATABASE_USERNAME=root
MATOMO_DATABASE_PASSWORD=npL4VEBERKGgirs44
MATOMO_DATABASE_DBNAME=matomo_tracking

Mapping to website

You can use either Nginx or HAproxy to setup domain and forward traffic to the correct port. With Matomo, you don’t need to have domain configuration. You only need to forward the traffic (using Nginx, HAProxy) to the right port.

Leave a Comment