docker.recipes

Matomo Web Analytics

beginner

Privacy-focused Google Analytics alternative for web analytics.

Overview

Matomo (formerly Piwik) is an open-source web analytics platform that serves as a privacy-focused alternative to Google Analytics. Originally launched in 2007, Matomo has become the leading self-hosted analytics solution, offering complete data ownership and GDPR compliance while providing comprehensive visitor tracking, conversion analysis, and behavioral insights. Unlike cloud-based analytics services, Matomo gives organizations full control over their data collection and storage. This stack combines Matomo with MariaDB to create a robust analytics infrastructure that processes visitor data efficiently while maintaining data sovereignty. MariaDB's enhanced MySQL compatibility ensures optimal performance for Matomo's data-intensive operations, while its Aria storage engine provides better crash recovery for analytics data. The combination leverages MariaDB's improved thread pool handling to manage concurrent visitor tracking requests and complex report generation queries simultaneously. This configuration is ideal for organizations requiring GDPR compliance, companies seeking independence from third-party analytics providers, and businesses needing detailed visitor insights without data sharing restrictions. Privacy-conscious websites, European organizations under strict data protection laws, and enterprises managing sensitive customer data will find this self-hosted analytics solution particularly valuable for maintaining complete control over visitor information.

Key Features

  • Real-time visitor tracking with heatmaps, session recordings, and conversion funnel analysis
  • GDPR-compliant data collection with built-in privacy controls and cookie consent management
  • Google Analytics data import wizard for migrating historical analytics data
  • Custom dimension tracking for e-commerce goals, form submissions, and event monitoring
  • MariaDB's Aria storage engine optimized for analytics workloads with better crash recovery
  • Multi-site analytics management from a single Matomo installation
  • Advanced segmentation and custom reporting with scheduled email delivery
  • Plugin ecosystem supporting A/B testing, cohort analysis, and marketing attribution

Common Use Cases

  • 1E-commerce websites tracking conversion funnels and customer behavior analytics
  • 2European businesses requiring GDPR-compliant visitor analytics without third-party data sharing
  • 3Marketing agencies managing analytics for multiple client websites from one dashboard
  • 4Content publishers analyzing article performance and reader engagement metrics
  • 5SaaS companies tracking user onboarding flows and feature adoption rates
  • 6Educational institutions monitoring course completion and student portal usage
  • 7Healthcare organizations needing HIPAA-compliant website analytics with data residency

Prerequisites

  • Minimum 1GB RAM for MariaDB operations and Matomo report generation
  • Port 8080 available for Matomo web interface access
  • Environment variables DB_PASSWORD and DB_ROOT_PASSWORD configured in .env file
  • Understanding of JavaScript tracking code implementation for website integration
  • Basic knowledge of analytics concepts like goals, conversions, and custom dimensions

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 matomo:
3 image: matomo:latest
4 container_name: matomo
5 environment:
6 - MATOMO_DATABASE_HOST=db
7 - MATOMO_DATABASE_ADAPTER=mysql
8 - MATOMO_DATABASE_TABLES_PREFIX=matomo_
9 - MATOMO_DATABASE_USERNAME=matomo
10 - MATOMO_DATABASE_PASSWORD=${DB_PASSWORD}
11 - MATOMO_DATABASE_DBNAME=matomo
12 volumes:
13 - matomo-data:/var/www/html
14 ports:
15 - "8080:80"
16 depends_on:
17 - db
18 networks:
19 - matomo-network
20 restart: unless-stopped
21
22 db:
23 image: mariadb:10.11
24 container_name: matomo-db
25 environment:
26 - MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
27 - MYSQL_DATABASE=matomo
28 - MYSQL_USER=matomo
29 - MYSQL_PASSWORD=${DB_PASSWORD}
30 volumes:
31 - mariadb-data:/var/lib/mysql
32 networks:
33 - matomo-network
34 restart: unless-stopped
35
36volumes:
37 matomo-data:
38 mariadb-data:
39
40networks:
41 matomo-network:
42 driver: bridge

.env Template

.env
1# Matomo Analytics
2DB_PASSWORD=secure_matomo_password
3DB_ROOT_PASSWORD=secure_root_password

Usage Notes

  1. 1Web UI at http://localhost:8080
  2. 2Complete installation wizard
  3. 3Add tracking code to websites
  4. 4GDPR compliant analytics
  5. 5Importers for Google Analytics

Individual Services(2 services)

Copy individual services to mix and match with your existing compose files.

matomo
matomo:
  image: matomo:latest
  container_name: matomo
  environment:
    - MATOMO_DATABASE_HOST=db
    - MATOMO_DATABASE_ADAPTER=mysql
    - MATOMO_DATABASE_TABLES_PREFIX=matomo_
    - MATOMO_DATABASE_USERNAME=matomo
    - MATOMO_DATABASE_PASSWORD=${DB_PASSWORD}
    - MATOMO_DATABASE_DBNAME=matomo
  volumes:
    - matomo-data:/var/www/html
  ports:
    - "8080:80"
  depends_on:
    - db
  networks:
    - matomo-network
  restart: unless-stopped
db
db:
  image: mariadb:10.11
  container_name: matomo-db
  environment:
    - MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
    - MYSQL_DATABASE=matomo
    - MYSQL_USER=matomo
    - MYSQL_PASSWORD=${DB_PASSWORD}
  volumes:
    - mariadb-data:/var/lib/mysql
  networks:
    - matomo-network
  restart: unless-stopped

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 matomo:
5 image: matomo:latest
6 container_name: matomo
7 environment:
8 - MATOMO_DATABASE_HOST=db
9 - MATOMO_DATABASE_ADAPTER=mysql
10 - MATOMO_DATABASE_TABLES_PREFIX=matomo_
11 - MATOMO_DATABASE_USERNAME=matomo
12 - MATOMO_DATABASE_PASSWORD=${DB_PASSWORD}
13 - MATOMO_DATABASE_DBNAME=matomo
14 volumes:
15 - matomo-data:/var/www/html
16 ports:
17 - "8080:80"
18 depends_on:
19 - db
20 networks:
21 - matomo-network
22 restart: unless-stopped
23
24 db:
25 image: mariadb:10.11
26 container_name: matomo-db
27 environment:
28 - MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
29 - MYSQL_DATABASE=matomo
30 - MYSQL_USER=matomo
31 - MYSQL_PASSWORD=${DB_PASSWORD}
32 volumes:
33 - mariadb-data:/var/lib/mysql
34 networks:
35 - matomo-network
36 restart: unless-stopped
37
38volumes:
39 matomo-data:
40 mariadb-data:
41
42networks:
43 matomo-network:
44 driver: bridge
45EOF
46
47# 2. Create the .env file
48cat > .env << 'EOF'
49# Matomo Analytics
50DB_PASSWORD=secure_matomo_password
51DB_ROOT_PASSWORD=secure_root_password
52EOF
53
54# 3. Start the services
55docker compose up -d
56
57# 4. View logs
58docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/matomo-analytics/run | bash

Troubleshooting

  • Matomo shows database connection error: Verify MariaDB container is running and DB_PASSWORD matches in both services
  • Installation wizard fails at database step: Check that MATOMO_DATABASE_HOST points to 'db' service name
  • Tracking code not recording visits: Ensure JavaScript tracking code is properly embedded before closing </head> tag
  • MariaDB container crashes during startup: Increase Docker memory allocation to minimum 1GB for stable operation
  • Reports loading slowly or timing out: Optimize MariaDB performance by increasing innodb_buffer_pool_size in database configuration
  • Archive processing fails with memory errors: Add PHP memory limit environment variable MATOMO_GENERAL_MEMORY_LIMIT_WHEN_ARCHIVING=2048M

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Ad Space